Linq查询2个字段的最大值

Mic*_*hel 0 linq

我认为标题有点神秘,这就是我想要做的......

我在我的表格中有两个日期时间字段.现在我想选择最大(即未来最远)日期大于'今天'的行

few examples: (today is 6-22)
date1: null, date2: null : no match, all lower than now
date1: null, date2: 5-31: no match, all lower than now
date1: null, date2: 6-23: match, 6-23 is larger than now
date1: 5-31, date2: 7-23: match, 6-23 is larger than now
date1: 7-21, date2: 1-23: match, 7-21 is larger than now
date1: 7-21, date2: null: match, 7-21 is larger than now
Run Code Online (Sandbox Code Playgroud)

所以在一些伪代码中:

select*from table where(max(date2,date2))> now

此致,米歇尔

Meh*_*ari 5

这是你想要的(我转换了你的SQL):

from row in table
where (row.Date1 != null && row.Date1 > DateTime.Now) || 
      (row.Date2 != null && row.Date2 > DateTime.Now)
select row
Run Code Online (Sandbox Code Playgroud)