我正在開發一個使用asp.net C#和VS2012 Express的MVC Web應用程序。Linq一對多聯盟
我有一個表(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();
感謝您的幫助。
問題是什麼?哪部分不工作? –