我想要的是在我的查询中包含3个表,并仅选择最后的表字段。
[WebMethod]
public Project[] GetAlll(int passeid)//passed id is the id of fieldteammeber table I am passing
{
var arr = db.Project.Include("FieldTeamMember")
.Include("FieldTeam")
.Where(ft_id=ftm_id and ft_mid=prj_ftm_id and FTM_ID=passeid)
.ToArray();
return arr;
}
想要选择项目表字段。模型中的表之间有F键。
答案 0 :(得分:1)
我认为这是您根据描述查找的查询:
int memberId = 1;
var projects = db.Projects
.Where(p => p.FieldTeam
.FieldTeamMembers.Any(ftm => ftm.Id == memberId));
或者,如果这对您更具可读性:
int fieldTeamMemberId = 1;
var projects = db.FieldTeamMembers.Where(ftm => ftm.Id == memberId)
.Select(ftm => ftm.FieldTeam.Project)
.Distinct();