linq比较2列表
var companytoexclude = from c in db.Companies
from p in c.Projects
where p.ProjectEndDate == null
select c;
var list = from m in db.Members.Include("Companies.Projects.Experiences")
where m.MemberId == id
select m;
如何排除在 companytoexclude 列表中的公司?
会员有多家公司
公司有很多项目
项目有很多经验
K我解决了它。 所以我所做的只是添加,
foreach (Company c in companytoexclude )
{
list .First().Companies.Remove(c);
}
所以有更容易显示的吗? 我想要具有公司列表的成员,而不仅仅是公司。
现在一些数据
Member
MemberId Name
2011 Jet
Company
CompanyId MemberId CompanyName
18 2011 Company1
29 2011 Company2
ProjectId CompanyId ProjectName ProjectEndDate
1 29 Project1 2008-08-01 00:00:00.000
2 29 Project2 2009-08-01 00:00:00.000
3 18 Project3 NULL
我希望它返回除company1和project3之外的所有数据
var companytoexclude = from c in db.Companies
from p in c.Projects
where p.ProjectEndDate == null
select c;
var list = from m in db.Members.Include("Companies.Projects.Experiences")
where m.MemberId == id
select m;
how do I exclude companies that are in companytoexclude in list?
Member have many company
company have many project
project have many experiences
K I kind of solved it.
So what I did is just add in
foreach (Company c in companytoexclude )
{
list .First().Companies.Remove(c);
}
so is there a easier to show this?
I want the member with list of companies, not just companies.
some data
Member
MemberId Name
2011 Jet
Company
CompanyId MemberId CompanyName
18 2011 Company1
29 2011 Company2
ProjectId CompanyId ProjectName ProjectEndDate
1 29 Project1 2008-08-01 00:00:00.000
2 29 Project2 2009-08-01 00:00:00.000
3 18 Project3 NULL
now I want it to return everything but company1 and project3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
怎么样:
这只会返回不包含您试图排除的任何公司的成员。
请注意,鉴于您指定了 MemberId,无论如何我几乎只期望一个结果......目前还不清楚您要做什么。
如果您希望排除该单个成员中除公司之外的所有公司,很简单:
如果这不是您想要的,请澄清您的问题。
另请注意,您的
companiesToExclude
查询一开始可能并不正确。您是否试图排除所有拥有结束日期为空的任何项目的公司?如果是这样,您想要:How about:
That will only return members which don't include any companies which you're trying to exclude.
Mind you, given that you're specifying a MemberId, I'd pretty much only expect one result anyway... it's unclear what you're trying to do.
If you want all the companies from that single member except the companies to exclude, it's easy:
If that's not what you're after, please clarify your question.
Also note that your
companiesToExclude
query may well not be right to start with. Are you trying to exclude all companies with any project with a null end date? If so, you want: