-4

必須の 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();
4

3 に答える 3

1

1つの方法は次のようになります。

db.polls.Where(p => p.id == polls.Where(x => x.publish_at == polls.Max(y => y.publish_at)).Max(x => x.id));

このような別の方法:

from p in db.polls
where p.id == (from x in db.polls
               where x.id == (from y in db.polls
                              where y.publish_at == db.polls.Max(y => y.publish_at)
                              select y.id).Max())
               select x.id).Max())
select p;
于 2012-08-09T15:12:47.043 に答える
0
var query = from p in context.Polls
            where p.id == (from p2 in context.Polls
                           where p2.publish_at == context.Polls.Max(x => x.publish_at)
                           select p2).Max(y => y.id)
            select p; 
于 2012-08-09T15:10:19.837 に答える
0

これは美しく機能します:

var qry = db.Polls.Where(p => p.id == db.Polls.Where(x => x.publish_at == db.Polls.Where(y => y.publish_at<=System.DateTime.Today).Max(y=>y.publish_at)).Max(x => x.id) && p.status.Equals(PollStatus.Active)).FirstOrDefault(); 
于 2012-08-10T10:49:59.173 に答える