i 几周前,我曾问过这个问题,但愿得到任何建议的答复。
i 有一个从xml文件返回的活动清单,如下所示:
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 现在需要查询我的数据库,以配合与活动同等的活动。 从上述方法返回。 因此,我有这样的想法:
* E/CN.6/2009/1。 Id in GetEventIdsByEventDate
如何利用LINQ这样做
thanks kb
根据你的建议,衍生方法如下:
public IEnumerable<EventFeed> foo(DateTime str)
{
var foo = from f in GetAllEventsFromDatabase().ToList()
where GetAllEventsByDate(str).Contains(f.EventShowCode)
select e;
return (IEnumerable<EventFeed>) foo;
}
但是,在汇编中,我有以下错误:
Error 7 The type arguments for method System.Linq.Enumerable.Contains<TSource>(System.Collections.Generic.IEnumerable<TSource>, TSource) cannot be inferred from the usage. Try specifying the type arguments explicitly.
G. 清洁 数据库:
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);
}