tags

entity framework

[Entity Framework] Using Include with lambda expressions

I’m currently working on a project that uses Entity Framework 4. Even though lazy loading is enabled, I often use the ObjectQuery.Include method to eagerly load associated entities, in order to avoid database roundtrips when I access them: var query = from ord in db.Orders.Include("OrderDetails") where ord.Date >= DateTime.Today select ord; Or if I also want to eagerly load the product: var query = from ord in db.Orders.Include("OrderDetails.Product") where ord.Date >= DateTime.