System.NotSupportedException: Serializer for System.DateTime must implement IBsonDocumentSerializer to be used with LINQ.

beginer
beginer
Participant
1478 Points
49 Posts

Getting following error:

System.NotSupportedException: Serializer for System.DateTime must implement IBsonDocumentSerializer to be used with LINQ.
   at MongoDB.Driver.Linq.Linq3Implementation.Misc.DocumentSerializerHelper.GetMemberSerializationInfo(IBsonSerializer serializer, String memberName)
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MemberExpressionToAggregationExpressionTranslator.Translate(TranslationContext context, MemberExpression expression)
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.ConvertExpressionToAggregationExpressionTranslator.Translate(TranslationContext context, UnaryExpression expression)
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.BinaryExpressionToAggregationExpressionTranslator.Translate(TranslationContext context, BinaryExpression expression)
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ExpressionToFilterTranslator.TranslateUsingAggregationOperators(TranslationContext context, Expression expression)
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ExpressionToFilterTranslator.Translate(TranslationContext context, Expression expression, Boolean exprOk)
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ExpressionTranslators.AndExpressionToFilterTranslator.Translate(TranslationContext context, BinaryExpression expression)
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ExpressionToFilterTranslator.Translate(TranslationContext context, Expression expression, Boolean exprOk)
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.ExpressionToFilterTranslator.TranslateLambda(TranslationContext context, LambdaExpression lambdaExpression, IBsonSerializer parameterSerializer, Boolean asRoot)
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators.WhereMethodToPipelineTranslator.Translate(TranslationContext context, MethodCallExpression expression)
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToExecutableQueryTranslators.CountMethodToExecutableQueryTranslator.Translate[TDocument](MongoQueryProvider`1 provider, TranslationContext context, MethodCallExpression expression)
   at MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToExecutableQueryTranslators.ExpressionToExecutableQueryTranslator.TranslateScalar[TDocument,TResult](MongoQueryProvider`1 provider, Expression expression)

Anyone has any solution for it? I'm trying something:

var result = _applicationUoW.MyAction.Search<int>(request,
x =>
(request.FromDate == null || !request.FromDate.HasValue || request.FromDate <= x.Date.Date)
);
Views: 481
Total Answered: 1
Total Marked As Answer: 0
Posted On: 27-Oct-2023 02:16

Share:   fb twitter linkedin
Answers
beginer
beginer
Participant
1478 Points
49 Posts
         

Resolved myself. As mongo sterilizer checks type see here https://github.com/mongodb/mongo-csharp-driver/blob/master/src/MongoDB.Bson/Serialization/BsonMemberMap.cs

I just made comparison with same type and worked for me:

var result = _applicationUoW.MyAction.Search<int>(request,
x =>
(request.FromDate == null || !request.FromDate.HasValue || request.FromDate <= x.Date)
);
Posted On: 27-Oct-2023 22:39
 Log In to Chat