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

前端 未结 7 2259
借酒劲吻你
借酒劲吻你 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:45

    Another solution is to retrieve entity name using EntitySet.Name.
    You code will be:

    var context = new DBContext();  
    context.Organizations.Include(context.Assets.EntitySet.Name).Where(o => o.Id == id).Single()
    

提交回复
热议问题