我正在使用 asp.net C# 和 VS2012 Express 开发一个 MVC Web 应用程序。
我有一个表 ( ) 与其他两个表 (和)Organizations
具有一对多关系。所有三个表都包含一个字段来维护关系。所有三个表都有一个字符串字段。Comments
Proposals
OrganizationID
AddedBy
我想找到所有组织Organization.AddedBy="Joe"
或Comments.AddedBy="Joe"
或Proposals.AddedBy="Joe"
。
这些查询进行连接,但我正在寻找一个仅包含Organizations' fields
.
// Find organizations created by this person.
IQueryable<Organization> org = from m in context.Organizations
where m.AddedBy.Equals("Joe")
select m;
// Find Comments created by this person.
IQueryable<Comment> comment = from m in context.Comments
where m.AddedBy.Equals("Joe")
select m;
// Join our two queries.
IQueryable<Comment> organizations = (from item in org
join c in comment on item.OrganizationID equals c.OrganizationID
select item).Distinct();
// Find Proposals created by this person.
IQueryable<Proposal> proposal = from m in context.Proposals
where m.AddedBy.Equals("Joe")
select m;
// Join our two queries.
organizations = (from item in organizations
join c in proposal on item.OrganizationID equals c.OrganizationID
select item).Distinct();
谢谢你的帮助。