所需的 SQL 等效项:
select * from polls where (id=(select max(id) from polls where publish_at=(select max(publish_at) from polls where publish_at<='2012-08-10 00:00:00')) and status=1 )
我已经尝试过了,但它给出了 Null 而它应该返回一行。
var qry = db.Polls.Where(p => p.id == db.Polls.Where(x => x.publish_at == db.Polls.Max(y => y.publish_at) && x.publish_at <= System.DateTime.Today).Max(x => x.id) && p.status.Equals(PollStatus.Active)).FirstOrDefault();