我需要检查当前日期是否有任何记录。但AddOn
是可以约会的日期。如果我检查下面的条件是抛出错误,因为我正在尝试从null获取日期。
var cusRelationships = SvcClient.Client.Context.CusRelationships.Where(c =>
c.CustomerId == identity.rCustomerId &&
c.AddedOn.Value.Date == DateTime.Now.Date).Select(c => c).ToList();
如何比较当前日期的日期?
答案 0 :(得分:2)
在使用Value之前检查null。
var cusRelationships = SvcClient.Client.Context.CusRelationships.Where(c =>
c.CustomerId == identity.rCustomerId &&
c.AddedOn.HasValue &&
c.AddedOn.Value.Date == DateTime.Now.Date).Select(c => c).ToList();
答案 1 :(得分:0)
var cusRelationships = SvcClient.Client.Context.CusRelationships
.Where(c =>
c.CustomerId == identity.rCustomerId &&
c.AddedOn.HasValue &&
c.AddedOn.Value.ToShortDateString() == DateTime.Now.ToShortDateString())
.Select(c => c)
.ToList();