0

我想要的是在我的查询中包含 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 键。

4

1 回答 1

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();
于 2013-09-06T14:50:15.253 回答