Thursday, May 30, 2013

How to solve "null reference exception" problem when turn off ProxyCreationEnabled in Code first Entity framework?

If turn on lazy loading in entity framework by:
Configuration.ProxyCreationEnabled = false;
Will get null reference exception problem when try to get navigation properties.

Need to do eagerly loading for navigation property by include clause
using (var context = new BloggingContext())
{
    // Load all blogs and related posts
    var blogs1 = context.Blogs
                          .Include(b => b.Posts)
                          .ToList();

}

No comments:

Post a Comment