[CSHARP-466] Unsupported where clause Created: 07/May/12 Updated: 05/Apr/19 Resolved: 07/May/12 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 1.4.2 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor - P4 |
| Reporter: | Yakov D | Assignee: | Craig Wilson |
| Resolution: | Done | Votes: | 0 |
| Labels: | Expression, question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
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"); 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 |
| Comments |
| Comment by Yakov D [ 07/May/12 ] | ||||||||
|
I made several tests using different expressions and extension methods - works without any error. Thank you very much for help. | ||||||||
| Comment by Craig Wilson [ 07/May/12 ] | ||||||||
|
If you are going to be dynamically building expression like this, I'd highly suggest you not using the linq syntax and using the extension method syntax. The below code should work properly although I tested with a slight variant as I don't have any idea what your entities look like. Note that the dynamic expression is NOT compiled because we need to look at the expression tree, not the il code in order to pass the query to the server.
Let me know if you need further help. |