我试图从这个 Linq 查询中获取的是所有广告的列表,其中最近关联的日志与LogType.IsStatus == true
has a LogType.Name
已确认或已更新。需要明确的是,一个 Advert 有很多 Log,每个 Log 有一个 LogType。到目前为止,我有以下内容,但它在 LastOrDefault 上给了我一个错误 System.NotSupportedException。
var adverts = (from a in database.Adverts
let lastLog = (from l in a.Logs
where l.LogType.IsStatus == true
orderby l.Created_at
select l).LastOrDefault()
where (lastLog != null)
&&
(lastLog.LogType.Name == "Confirmed" || lastLog.LogType.Name == "Renewed")
orderby a.Created_at descending
select a).ToList();
LastOrDefault()
LINQ to Entities 不支持(请参阅here http://msdn.microsoft.com/en-us/library/bb738550.aspx#sectionSection7).
您可以通过更改来解决此问题order by
你的条款let
子查询到order by
descending
然后使用FirstOrDefault()
反而。
var adverts = (from a in database.Adverts
let lastLog = (from l in a.Logs
where l.LogType.IsStatus == true
orderby l.Created_at descending
select l).FirstOrDefault()
where (lastLog != null)
&&
(lastLog.LogType.Name == "Confirmed" || lastLog.LogType.Name == "Renewed")
orderby a.Created_at descending
select a).ToList();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)