[CSHARP-3873] Implement Invoke() to allow for dynamic predicate creation. Created: 22/Sep/21  Updated: 17/Nov/22

Status: Backlog
Project: C# Driver
Component/s: LINQ3
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Unknown
Reporter: Richard Collette Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Using the PredicateBuilder class as discussed here:
http://www.albahari.com/nutshell/predicatebuilder.aspx

When using the expression built by PredicateBuilder, which in this case is of type 

Expression<Func<Product, bool>>

to .Find() or to AsQueryable().Where():

I get the error

System.ArgumentException: Unsupported filter: Invoke(product => (product.FriendlyName.ToUpperInvariant() == "GOLF COURSES"), \{document}).
 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.TranslateTake(TakeExpression 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, ExpressionTranslationOptions translationOptions)
 at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Translate(Expression expression)
 at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
 at MongoDB.Driver.Linq.MongoQueryable.FirstOrDefaultAsync[TSource](IMongoQueryable`1 source, CancellationToken cancellationToken)

I am attempting to implement dynamic, nested OR predicates as mentioned in that article.



 Comments   
Comment by Dmitry Lukyanov (Inactive) [ 22/Sep/21 ]

Hello richard.collette@gmail.com , thanks for your suggestion.

We don't support this functionality in the current LINQ implementation, but this looks like an interesting idea that we will consider for new LINQ implementation that we're currently actively reviewing.

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