LINQ 2 Entities,如何在linq查询中检查DateTime.HasValue [英] LINQ 2 Entities , howto check DateTime.HasValue within the linq query
本文介绍了LINQ 2 Entities,如何在linq查询中检查DateTime.HasValue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个方法,该方法应该从称为ENTRY的表(& EntitySet)中获取最新消息的发布
I have this method that is supposed to get the latest messages posted, from the Table (& EntitySet) called ENTRY
////方法获取天"作为参数,用于新的TimeSpan(days,0,0,0); !!
///method gets "days" as parameter, used in new TimeSpan(days,0,0,0);!!
using (Entities db = new Entities())
{
var entries = from ent in db.ENTRY
where ent.DATECREATE.Value > DateTime.Today.Subtract(new TimeSpan(days, 0, 0, 0))
select new ForumEntryGridView()
{
id = ent.id,
baslik = ent.header,
tarih = ent.entrydate.Value,
membername = ent.Member.ToString()
};
return entries.ToList<ForumEntryGridView>();
}
这里DATECREATED在数据库中为空.我无法在此查询中放置如果" ...以任何方式进行检查吗?提前谢谢
Here the DATECREATED is Nullable in the database. I cant place "if"s in this query ... any way to check for that? Thx in advance
推荐答案
在DATECREATED
是null
的情况下您要做什么?
What do you want to do in case DATECREATED
is null
?
如果您只想忽略这些记录,请使用其他条件(或where
子句):
If you just want to ignore these records use an additional condition(or where
clause):
var entries = from ent in db.ENTRY
where ent.DATECREATED.HasValue && ent.DATECREATED.Value > ...
这篇关于LINQ 2 Entities,如何在linq查询中检查DateTime.HasValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文