tags:

views:

92

answers:

2
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

A: 

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.

Anton
+1  A: 

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