开发者

Joins in Entity Framework need help

I have 3 Tables:

Region:

ID,
Name

District

ID,
RegionID,
Name

City

ID,
DistrictID,
Name

When I write like this:

var result = (from item in db.Region.Include("District.City")
              select item).ToList();

In result I have objects dependent on each other开发者_Python百科

For example: In Region I have 2 objects, in District 4 objects and in City 8 objects

I want to write this with Linq Join, not with include()

Can you help me??


You can use join instead of include, but your relations won't change

var result = from r in db.Region
             join d in db.District on r.ID equals d.RegionID
             join c in db.City on d.ID equals c.DistrictID
             where r.ID == 1
             select r;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜