This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I am trying to use PredicateBuilder from LinqKit (http://www.albahari.com/nutshell/predicatebuilder.aspx) with LinqSpeed but am running into problems. I'm finding that I can use the PredicateBuilder's True and False methods when composed into a larger expression using the Or and And methods but not on their own. I get: NotSupportedException: Specified method is not supported. I fired up LinqPad with the Lightspeed driver and connected using my model and found that writing the equivalent LINQ expression would bomb with the same error.
from o in Orders However the above works with LINQ to SQL. The following (LINQ to Objects) also works, which leads me to believe this is a bug in Lightspeed.
from o in new int[] {1,2,3} LINQ to SQL works with all of the following where Lightspeed fails on all of them: from o in Orders from o in Orders from o in Orders
|
|
|
We have only limited support for boolean literals or boolean client-side expressions in Where clauses. Basically we require that the Where clause contain *some* predicate that involves a LightSpeed query. You can then and or or it with booleans. For example: int someValue = 1; from o in Orders where someValue == 1 select o; // not supported We'd be happy to look at supporting where clauses that don't contain any LightSpeed criteria, but I think we'd need to better understand your use case in order to prioritise the work. Is this primarily for testing or do you have an application which would need to handle boolean literals? |
|
|
Basically I'm trying using an approach with Lightspeed that I've used successfully in a previous project using Entity Framework where we built reusable expressions to be passed into a Where call. For example I might want to grab some entities and filter by two optionals pieces of criteria that the user chooses at runtime. The criteria are combined using And or Or and then to form a single expression that is passed into the Where call. If the user doesn't select either of the criteria, you want the Where call to not filter and so passing an expression that evaluates to True is the way to do this. I can get around this with code checks and not do a Where call but was hoping to do this the same way as before as the code is tidier. The link I provided in the first post explains the approach in more detail. |
|
|
Thanks, we'll take a look at this. As a workaround, if you're using numeric IDs, you can use Id comparisons as your "true" and "false" building blocks: * Id > 0 will always be true * Id < 0 will always be false These won't be optimised away the way constant true and false clauses will be, but they should still run extremely efficiently and will allow you to keep the tidy "no-ifs" query building style. |
|