Using PredicateBuilder return NotSupportedException [BUG]
See original GitHub issueVersion 5.0.9 Code to Reproduce For simplicity:
- I use a very simple query to describe the issue
- I’m using LINQPad,
void Main()
{
var cs = new ConnectionString
{
Filename = @"c:\mydb.db",
Password = @"MyP@55w0rd"
};
using (var db = new LiteDatabase(cs))
{
var col = db.GetCollection<Product>("Prods");
col.Insert(new Product{ Name="AAA"});
col.Insert(new Product{ Name="AEE"});
var predicate = PredicateBuilder.False<Product>();
predicate = predicate.Or(p => p.Name.Contains("A"));
col.Find(predicate).Count().Dump(); //<== NotSupportedException
}
}
public class Product
{
public int Id{get;set;}
public string Name{get;set;}
}
Expected behavior The Count method should return the number of documents
Stacktrace
at LiteDB.LinqExpressionVisitor.Resolve(Boolean predicate)
at LiteDB.BsonMapper.GetExpression[T,K](Expression`1 predicate)
at LiteDB.LiteCollection`1.Find(Expression`1 predicate, Int32 skip, Int32 limit)
at UserQuery.Main(), line 20
Exception Message
Invalid BsonExpression when converted from Linq expression: f => (False OrElse Invoke(p => p.Name.Contains("A"), f)) - `(((@p0) = true) OR @.Name LIKE ('%' + @p1 + '%')$)`
LiteException
Unexpected token `$` in position 49.
Any help would be greatly appreciated.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
Top Results From Across the Web
Stackoverflow Exception using PredicateBuilder with Entity ...
I have added my own Expression builder engine, i.e. much better way to generate the Predicate. PredicateBuilder works well with LINQ to Object, ......
Read more >PROBLEM with LINQKit pluggable expressions on OData ...
When I switched back to the VB version of the query, it works as expected (i got the server-side filtering OData query) when...
Read more >Combine predicates with PredicateBuilder
A predicate is a function that returns true or false for an item it evaluates. A query Where clause takes a predicate that...
Read more >A universal PredicateBuilder | Monty's Gush - WordPress.com
I don't use the famous Albahari PredicateBuilder because it doesn't work so well with Entity Framework or the latest version of NHibernate.
Read more >Create dynamic Linq queries with Predicate Builder
Create dynamic Linq queries with Predicate Builder ... This is a delegate who acts on the given argument, but does not return anything....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@toumir This issue has been fixed in the master and its fix will be present in the next incremental release. In the meantime, I suggest you use the
ILiteQueryable<T>
interface fromcol.Query()
, for which I gave an example in my previous comment.I’m also looking for a fix for this. I have so very much code using PredicateBuilder that I really don’t want to rewrite, plus I am unsure how I can substitute col.Query() for every single instance (queries with dynamic and complex and’s and or’s, using predicates with DeleteMany(), etc.).
@lbnascimento Am I missing some documentation page on how to use Query()? I can’t find anything.