[英]MongoDB C# Nullable Datetime Query
I'm trying to query a over mongoDB and I get the following error: 我正在尝试通过mongoDB查询,并且出现以下错误:
Unable to determine the serialization information for the expression: c.IndexMetadata.Indexed.
无法确定表达式的序列化信息:c.IndexMetadata.Indexed。 HasValue .
HasValue 。
where Indexed is a nullable datetime 其中Indexed是可为空的日期时间
my query is the following: 我的查询如下:
Collection.AsQueryable<Candidate>(c => !c.IndexMetadata.Indexed.HasValue || c.IndexMetadata.Updated.Value > c.IndexMetadata.Indexed.Value).ToList();
both indexed and updated are type of nullable datetime 索引和更新均为可空的datetime类型
I guess that's because there's no direct translation from HasValue into a mongo Query, any workaround? 我猜那是因为没有从HasValue到mongo Query的直接转换,有什么解决方法吗?
You can compare the DateTime?
您可以比较
DateTime?
to null instead of using HasValue
: 为null而不是使用
HasValue
:
Collection.AsQueryable<Candidate>(
c =>
c.IndexMetadata.Indexed == null ||
c.IndexMetadata.Updated.Value > c.IndexMetadata.Indexed.Value).
ToList();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.