I have something like the following many, many relationship tables.
public class Shop{ public int Id { get; set; } public virtual ICollection<ShopFacility> ShopFacilities { get; set; } } public class ShopFacility { public int Id { get; set; } public int ShopId { get; set; } public int FacilityId { get; set; } public virtual Shop Shop { get; set; } public virtual Facility Facility { get; set; } } public class Facility { public int Id { get; set; } public virtual ICollection<ShopFacility> ShopFacilities { get; set; } }
and get information about stores.
using (var context = new DataContext()) { return context.Shops.Include(s => s.ShopFacilities) .Include("ShopFacilities.Facility")
What I want to do is call the Include method with a Lambda expression for a many-many relationship instead of a string. I tried to implement as below code:
using (var context = new DataContext()) { return context.Shops.Include(s => s.ShopFacilities) .Include(s => s.ShopFacilities.Facility)
But, as you suppose, I can not compile it. Actually, the first code snippet works well, so basically it's good, however, I'm curious if there is work or not.
Any help would be appreciated
YU
linq-to-entities entity-framework ef-code-first
Yoo Matsuo Mar 09 2018-11-11T00: 00Z
source share