我有一个如下所示的查询:
var TheOutput = from u in MyDC.TheTable
where ....
orderby u.TheDateTimeUsed
select new MyModel()
{
....
TheDateCreated = u.TheDateTimeCreated,
TheDateUsed = u.TheDateTimeUsed
...
};
return TheOutput.Take(10).ToList();
u.DateTimeUsed是一个可以为空的日期。如果值为null,那么我希望这些记录首先出现在我正在加载的10个列表中。
我该怎么做?
感谢。
答案 0 :(得分:3)
也许是这样的:
var TheOutput = from u in MyDC.TheTable
where ....
orderby !u.TheDateTimeUsed.HasValue
orderby u.TheDateTimeUsed
select new MyModel()
{
....
TheDateCreated = u.TheDateTimeCreated,
TheDateUsed = u.TheDateTimeUsed
...
};
你也可以这样做:
var TheOutput = from u in MyDC.TheTable
where ....
orderby u.TheDateTimeUsed??DateTime.MinValue
select new MyModel()
{
....
TheDateCreated = u.TheDateTimeCreated,
TheDateUsed = u.TheDateTimeUsed
...
};
不如第一个好。