Linq-to-entities - Include() method not loading

前端 未结 5 1236
既然无缘
既然无缘 2020-11-28 07:18

If I use a join, the Include() method is no longer working, eg:

from e in dc.Entities.Include(\"Properties\")
join i in dc.Items on e.ID equals i.Member.ID
w         


        
5条回答
  •  爱一瞬间的悲伤
    2020-11-28 07:56

    So what is the name of the navigation property on "Entity" which relates to "Item.Member" (i.e., is the other end of the navigation). You should be using this instead of the join. For example, if "entity" add a property called Member with the cardinality of 1 and Member had a property called Items with a cardinality of many, you could do this:

    from e in dc.Entities.Include("Properties")
    where e.Member.Items.Any(i => i.Collection.ID == collectionID) 
    select e
    

    I'm guessing at the properties of your model here, but this should give you the general idea. In most cases, using join in LINQ to Entities is wrong, because it suggests that either your navigational properties are not set up correctly, or you are not using them.

提交回复
热议问题