开发者

Joins in Entity Framework need help

开发者 https://www.devze.com 2023-03-27 20:13 出处:网络
I have 3 Tables: Region: ID, Name District ID, RegionID, Name City ID, DistrictID, Name When I write like this:

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

精彩评论

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