我有这个标准的LINQ
var sidEvents = (from f in AppDelegate.Self.Subscription.Fred
from s in f.Sid
from e in s.Eve
where e.date >= oneWeek
select new {Title = e.type, Data = e.data, Date = e.date}).ToList();
我已经改变了一些东西,现在我得到一个Eve对象的列表,其中的where条件就像这样
var sidEvents = AppDelegate.Self.DBManager.GetListOfEvents("type", "EatingOut").Where(t => t.date >= oneWeek).ToList();
有没有办法可以扩展这个LINQ查询以包含原始LINQ查询中的select new {...}?
答案 0 :(得分:3)
var sidEvents = AppDelegate.Self.DBManager.GetListOfEvents("type", "EatingOut")
.Where(t => t.date >= oneWeek)
.Select(e => new { Title = e.type, Data = e.data, Date = e.date }).ToList();
答案 1 :(得分:1)
也许你正在寻找这个:
var sidEvents = AppDelegate.Self.DBManager.GetListOfEvents("type", "EatingOut")
.Where(t => t.date >= oneWeek)
.Select(e => new {...})
答案 2 :(得分:1)
如果您更熟悉LINQ查询语法,可以
将第二个查询从方法语法转换为查询语法
var sidEvents = (from t in AppDelegate.Self.DBManager.GetListOfEvents("type", "EatingOut")
where t.date >= oneWeek
select t).ToList();
然后将select t
部分替换为new
表达式。