where 子句中的 IN 运算符

发布于 2024-08-19 17:59:38 字数 724 浏览 5 评论 0原文

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

我有 EventID 另一个 var varibale

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

类似这样的东西

    EventOrg.OrganizerID == MstrOrg.OrganizerID

    &&  EventOrg.EventID in EventID.ID

我如何才能实现此目的?

我会感谢你的帮助

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()

This work fine now i want to use IN Opeartor in the above Query.

in the EventOrganizer I have EventID now i want to select only Event ID exsist in EventOrganizer collection

I have EventID another var varibale

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

Something like this

where

    EventOrg.OrganizerID == MstrOrg.OrganizerID

    &&  EventOrg.EventID in EventID.ID

How I can achive this ?

I will appreciate your help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听,心雨的声音 2024-08-26 17:59:38

试试这个:

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
           }
         );  

Try this:

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
           }
         );  
猫腻 2024-08-26 17:59:38

如果您使用实体框架,则不能使用 Contains 语句,这在 Linq 中是一个简单的解决方案。因此,如果只是 Linq 2 实体,请使用像“where EventId.Contains(EventOrg.Id)”这样的 where 子句。

如果您确实使用实体框架,则必须根据 EventID 集合中的 Id 构建一个 or 表达式。

If you are using Entity Framework you can not use a Contains statement, which would be an easy solution in Linq. SO if it's just Linq 2 Entities, use a where clause like "where EventId.Contains(EventOrg.Id)"

If you are indeed using Entity Framework you will have to build an or expression based on the Id's in the EventID Collection.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文