Hi
i have a list of event Ids returned from an xml document as shown below
public IEnumerable<EventFeed> GetEventIdsByEventDate(DateTime eventDate)
{
return (from feed in xmlDoc.Descendants("Show")
from ev in feed.Elements("Event")
where Convert.ToDateTime(ev.Attribute("Date").Value).ToShortDateString() == eventDate.ToShortDateString()
select new EventFeed()
{
EventShowCode = feed.Attribute("Code").Value
}).ToList();
}
i now need to query my database to match events that equal the eventIds returned from the above method. so i would have something like:
select * from eventsdb where eventId in GetEventIdsByEventDate()
how can i do this using LINQ
i cant seem to get any of the answers working.
this is the method that looks up the eventIds from an XML feed
public IList<EventsDetails> GetEventIds(DateTime eventDate)
{
var eventids = (from feed in xmlDoc.Descendants("Show")
from ev in feed.Elements("Event")
where Convert.ToDateTime(ev.Attribute("Date").Value).ToShortDateString() == eventDate.ToShortDateString()
select new EventsDetails()
{
EventId = feed.Attribute("Code").Value
}).ToList();
return eventids;
}
this is the method that looks up the events in my database
public IEnumerable<EventFeed> GetAllEventsFromDatabase()
{
var allEvents = from eventsList in GetEventsList()
select new EventFeed()
{
EventName = eventsList.Title,
EventSummary = eventsList.Introduction,
EventShowCode = eventsList.EventId,
EventImageSmall = eventsList.EventImageThumbUrl,
EventUrl = eventsList.Url,
EventSortBy = eventsList.SortOrder
};
return allEvents.OrderBy(x => x.EventSortBy);
}
and this is the method to look up any matching eventIds in the XML that exist in my database
public IEnumerable<EventFeed> FilteredEvents(DateTime eventDate)
{
return GetAllEventsFromDatabase().Where(p => GetEventIds(eventDate).Contains<EventsDetails>(p.EventShowCode));
}
the project fails to build with the following error:
Error 9 Argument '2': cannot convert from 'string' to 'Events.EventsDetails'