我有一个 C# .Net Web 应用程序,我正在使用以下 LINQ 查询来获取用户创建或具有各种用户角色的不同提案列表。即使在 Union 和 Distinct 之后,要返回的列表也包含相同提案的欺骗。我究竟做错了什么?
var thereturn = FindAll(DetachedCriteria.For<Proposal>(),
new Order("CreateDate", false));
//get the proposals that aUser created
IList<Proposal> it =
thereturn.Where(proposal => proposal.CreatedBy.Equals(aUser)).ToList();
//get the proposals that aUser is a BOE Author
IList<Proposal> it2 =
thereturn.Where(proposal =>
proposal.BOEs.Any(boe =>
boe.Users.Where(a => a.Name == aUser).Any())).ToList();
//get all other proposals that aUser is on
IList<Proposal> it3 =
thereturn.Where(proposal =>
proposal.Users.Where(o => o.Name == aUser).Any()).ToList();
//now union with all other proposals that aUser is on
return it3.Union(it).Union(it2).
OrderByDescending(o=>o.CreateDate).Distinct().ToList();