[CSHARP-1592] Nullable comparison throws ArgumentException - {"Unsupported filter Created: 07/Mar/16  Updated: 11/Mar/16  Resolved: 11/Mar/16

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 2.2.3
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Carlos Casanova Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I have a class with 2 Nullable DateTime properties.
The query that I'm trying to run is:

Repository.GetAll().Where(_ => _.DateDelivered.HasValue && _.DateDue.HasValue && _.DateDelivered.Value == _.DateDue.Value);

I'm getting the following exception:
System.ArgumentException {"Unsupported filter: (Convert(

{document}{DateDelivered}) == Convert({document} {DateDue}

))."}
StackTrace :
at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Translators.PredicateTranslator.TranslateAndAlso(BinaryExpression node)
at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Translators.PredicateTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslateWhere(WhereExpression node)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.TranslatePipeline(PipelineExpression node)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Translators.QueryableTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Translate(Expression expression)
at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Execute(Expression expression)
at MongoDB.Driver.Linq.MongoQueryableImpl`2.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Moravia.SymLite.Toolkit.Toolkit.Main(String[] args) in c:_work\projects\symfonie-lite\Toolkit\Toolkit.Main.cs:line 29
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()



 Comments   
Comment by Craig Wilson [ 11/Mar/16 ]

Hi Carlos,

I've taken a look and nullable types work as they are supposed to. The issue with your query is that MongoDB does not allowing comparing two fields to each other. You can only compare fields to a constant. Because of this restriction, we cannot convert the query. It is simply not valid MongoDB syntax.

I'm going to close this ticket as Works as Designed. Feel free to ping back if you feel this is an error.
Craig

Generated at Wed Feb 07 21:40:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.