像这样的东西应该工作:
查询语法:
Take
不支持,所以必须作为扩展方法调用:
var query = (from term in EM.SearchHistory
group term by term.searchterm into g
let item = new
{
searchterm = g.Key,
first = g.OrderBy(t => t.created).First(),
}
where item.first.createdby == "USERNAME"
orderby item.first.created
select new
{
item.searchterm,
item.first.created,
})
.Take(5)
;
方法语法:
var query = EM.SearchHistory
.GroupBy(term => term.searchterm)
.Select(g => new
{
searchterm = g.Key,
first = g.OrderBy(t => t.created).First(),
})
.Where(item => item.first.createdby == "USERNAME")
.OrderBy(item => item.first.created)
.Select(item => new
{
item.searchterm,
item.first.created,
})
.Take(5)
;