gpt4 book ai didi

c# - where 子句中的 IN 运算符

转载 作者:太空宇宙 更新时间:2023-11-03 14:32:58 26 4
gpt4 key购买 nike

List<HelprClass.Organizer> org = 
( from EventOrg in cntx.EventOrganizer
from MstrOrg in cntx.Organizer
where EventOrg.OrganizerID == MstrOrg.OrganizerID
Select new HelprClass.Organizer
{
OrganizerName = MstrOrg.OrganizerName
}).ToList()

现在我想在上面的查询中使用 IN Opeartor。这工作正常。

在 EventOrganizer 中我有 EventID 现在我只想选择 EventOrganizer 集合中存在的事件 ID

我有另一个 var varibale 的 EventID

Var EventID= From EvntID in Evetn Select new {ID= EvntID.EventID};

类似这样的东西

在哪里

    EventOrg.OrganizerID == MstrOrg.OrganizerID

&& EventOrg.EventID in EventID.ID

我怎样才能做到这一点?

我会感谢你的帮助

最佳答案

试试这个:

var EventIDs = from EvntID in Event select EvntID.EventID;

var org = (from EventOrg in cntx.EventOrganizer
from MstrOrg in cntx.Organizer
where EventOrg.OrganizerID == MstrOrg.OrganizerID
select new {E=EventOrg, M=MstrOrg}
).ToList();


org = org
.Where(o => EventIDs.Contains(o.E.EventID) )
.Select(o => new HelprClass.Organizer
{
OrganizerName = o.M.OrganizerName
}
);

关于c# - where 子句中的 IN 运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2160813/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com