这是我的edmx图。
我正在尝试获取特定ProfileId的所有驱动器
这是我写的查询
var prof = (from p in pe.UserDrives.Include("Drive")
where p.ProfileId == Cuser.ProfileId
select p).ToList();
数据:
Drive
Id googleAccount RefreshToken AccessToken
1 Cloud NULL NULL
2 Storage NULL NULL
UserDrive
DriveId Id ProfileId
1 1 1
2 2 1
我得到的结果是profileId = 1的驱动器信息将是来自userdrive的2条记录及其相应的驱动器信息
相反,我想要选择的配置文件有一个驱动器记录列表
请承担新问题。我刚刚学习
答案 0 :(得分:1)
您只需选择Drive
属性而不是UserDrive
。像这样:
var prof = (from p in pe.UserDrives.Include("Drive")
where p.ProfileId == Cuser.ProfileId
select p.Drive).ToList();
答案 1 :(得分:1)
请尝试
var prof = (from p in Profile
join ud in UserDrive on p.id equals ud.profileId
join d in drive on ud.driveid equals d.Id
where p.ProfileId == Cuser.ProfileId
select new { p,ud,d}).tolist();
string a = prof.p.columnname;
string b = prof.ud.columnname;
string c = prof.d.columnname;