EF4 LINQ Include(string) alternative to hard-coded string?

前端 未结 7 2261
借酒劲吻你
借酒劲吻你 2020-12-29 11:13

Is there any alternative to this:

Organizations.Include(\"Assets\").Where(o => o.Id == id).Single()

I would like to see something like:<

相关标签:
7条回答
  • 2020-12-29 11:47

    In EF 4.1, there is a built-in extension method for this.

    You must have a reference to "EntityFramework" assembly (where EF 4.1 lives) in your project and use System.Data.Entity.

    using System.Data.Entity; 
    

    If you want to include nested entities, you do it like this:

            db.Customers.Include(c => c.Orders.Select(o => o.LineItems))
    

    Not sure if this works for EF4.0 entities (ObjectContext based).

    0 讨论(0)
提交回复
热议问题