What's hot ? (and I mean really ...) - scroll down for more
1).  Code Templating - advanced usage of delegates & generics: my slides & demos are available for download! CodeProject article is also available.

2).  My series "TDD in the eyes of a simpleminded" is in progress(including code!): preface, part1, part2, Q&A 1, Manual Stub .vs. Mock Stub

3).  TDD Workshop: SeeCompass v0.1 and v0.2 are out.
# Monday, October 02, 2006

Let's say we have an entity named "Blog" that has many "Post"s in it:

[ActiveRecord("Blogs")]
public class Blog : ActiveRecordValidationBase<Blog>
{
   private IList _posts;
   // ... snipped ... 

   [HasMany(typeof (Post), 
      Table = "Posts"
      Lazy = true,
      ColumnKey = "BlogId")]
   public IList Posts
   {
      get { return _posts; }
      set { _posts = value; }
   }
   
   // ... snipped ...
}

Configure your web application to support lazy loading:

  1. Use the isWeb="true" attribute in your web.config file - look here for "how to".
  2. Open a SessionScope at the beginning of each request - look here for "how to".


Now, How do you know if lazy loading is (really)enabled:

Blog b = Blog.Find(1);
bool isInit = NHibernateUtil.IsInitialized(b.Posts);

If isInit shows true, then lazy loading wasn't enabled and you need to make sure you didn't miss anything. if it shows false - lazy loading is on!

Thanks for Ayende Rahien for pointing on NHibernateUtill, this can be quite handy.

Posted by Oren Ellenbogen 
02/10/2006 08:01, Israel time UTC+02:00,     Comments [6]  |  Related posts:
ActiveRecord & Atlas POC