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 Opeart。
在EventOrganizer中我有EventID现在我想在EventOrganizer集合中只选择事件ID exsist
我有EventID另一个var varibale
Var EventID= From EvntID in Evetn Select new {ID= EvntID.EventID};
像这样的东西
其中
EventOrg.OrganizerID == MstrOrg.OrganizerID
&& EventOrg.EventID in EventID.ID
我怎么能做到这一点?
我将非常感谢您的帮助
答案 0 :(得分:1)
试试这个:
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
}
);
答案 1 :(得分:0)
如果您使用的是Entity Framework,则无法使用Contains语句,这在Linq中是一个简单的解决方案。如果它只是Linq 2实体,请使用where where子句,例如“where EventId.Contains(EventOrg.Id)”
如果您确实在使用Entity Framework,则必须根据EventID Collection中的Id构建或表达。