Details
-
Task
-
Resolution: Done
-
Minor - P4
-
None
-
1.4.2
-
None
-
Tested on win 7, .net 4.0
Description
Tried to use expressions to build where clause dynamically, but couldn't use even simple expression - throws error "Unsupported where clause: <InvocationExpression>"
Here is code snippet.
var entry = Expression.Parameter(typeof(BasePriceEntry), "c");
var x = Expression.Lambda<Func<BasePriceEntry, bool>>(Expression.Equal(entry.Property("CatId"), Expression.Constant(cat)), entry).Compile();
var db = Server.GetDatabase(DB);
using (Server.RequestStart(db))
{ var collection = db.GetCollection<BasePriceEntry>(COLLECTION_CONST); var items = from c in collection.AsQueryable<BaseEntry>() where x(c) && c.LowerText.Contains(filterText.ToLower()) select c; return items.ToArray(); }Here is stack trace.
в MongoDB.Driver.Linq.SelectQuery.BuildQuery(Expression expression) в C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:строка 784
в MongoDB.Driver.Linq.SelectQuery.BuildAndAlsoQuery(BinaryExpression binaryExpression) в C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:строка 269
в MongoDB.Driver.Linq.SelectQuery.BuildQuery(Expression expression) в C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:строка 751
в MongoDB.Driver.Linq.SelectQuery.BuildQuery() в C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:строка 113
в MongoDB.Driver.Linq.SelectQuery.Execute() в C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:строка 122
в MongoDB.Driver.Linq.MongoQueryProvider.Execute(Expression expression) в C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\MongoQueryProvider.cs:строка 147
в MongoDB.Driver.Linq.MongoQueryable`1.GetEnumerator() в C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq\MongoQueryable.cs:строка 81
в System.Linq.Buffer`1..ctor(IEnumerable`1 source)
в System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
в dblib.DataBaseLayer.FindEntries(String filterText, Int32 cat, Int32 pr1, Int32 pr2) в F:\Projects\my\site\dblib\DataBaseLayer.cs:строка 147