If anyone's interested, I answered this one in StackOverflow:
http://stackoverflow.com/questions/3555716/caching-not-working-for-associated-entities-unless-lazy-loading-specified-in-map/3556324#3556324
Diego
On Tue, Aug 24, 2010 at 06:40, Chuck Boyde <[email protected]> wrote:
> I am having a problem getting associated entities to be cached unless
> they are specified (Not.LazyLoad() in mapping). If I build up a query
> in Criteria or Linq the Main Entity is cached, but not associated
> entities.
>
> IList<NewsItem> news;
> using (var session = factory.OpenSession())
> {
> Console.WriteLine("First Query");
> news = session.CreateCriteria(typeof(NewsItem))
> .SetCacheable(true)
> .SetFetchMode("Author", FetchMode.Eager) //
> associated entity eager loaded
> .List<NewsItem>();
> }
> foreach (var item in news)
> {
> Console.WriteLine("Author: " + item.Author.Name); //
> works fine first time
> }
>
> using (var session = factory.OpenSession())
> {
> Console.WriteLine("");
> Console.WriteLine("Second Query");
> news = session.CreateCriteria(typeof(NewsItem))
> .SetCacheable(true)
> .SetFetchMode("Author", FetchMode.Eager)
> .List<NewsItem>();
> }
> foreach (var item in news)
> {
> Console.WriteLine("Author: " + item.Author.Name); //
> fails with NHibernate.LazyInitializationException
> }
>
> I want to avoid having to eager load the associations via the mapping
> files. Anyone else having a similar problem.
>
> Any feedback appreciated.
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.