NoRM
NoRM copied to clipboard
Exception using complex where clause
I get the following exception when trying to do a rather complex query:
Unable to cast object of type 'System.Linq.Expressions.BinaryExpression'
to type 'System.Linq.Expressions.MemberExpression'.
Query: var result =
Context.Query<Subscription>().
Where(s => s.LastReportTicks + s.Interval * TicksPerDay < NowTicks).
OrderBy(s => s.LastReportTicks + s.Interval * TicksPerDay);
at Norm.Linq.MongoQueryTranslator.HandleSort(Expression exp, OrderBy orderby)
in MongoQueryTranslator.cs
The cast to (MemberExpression) assumes there's only a simple member access... I fiddled around a bit, but I was unable to fix this so far.
Since the orderby above is not supported by MongoDB, I think that doing it for the caller on the client side transparently will lead to people thinking that they're executing a sort somewhere remotely and getting the results back. In this case, I recommend users add a ".AsEnumerable()" after the .Where(), as one would do for complex queries in LINQ-To-SQL
I see your point. Still, we might want to provide a nicer exception - InvalidCast looks like a bug. Perhaps NotSupportedException would be better in this case?
Sounds like a "has no supported translation" exception thrown by LINQ to SQL.