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 creating a dynamic query based on some user input For this I am creating a QueryExpression that is constructed at the runtime. For part of the my query one of the filter is available to me in the form of LambdaExpression, as I am using the Dynamic LINQ API for resolve the filter condition from the string based expression. So I have something like below: string expr = "Cost > 200"; QueryExpression qe = null; // Adding some pre-prepared Query expressions to the main expressions qe &= someAdditionalFilter; Expression<Func<Employee, bool>> es = DynamicExpression.ParseLambda<Employee, bool>(expr); I want to do something like below: qe &= es; Now the issue is having a Lambda expression at hand how do I convert it to the QueryExpression so that i can do something like: qe &= LambdaExpressionToQueryExpression(es); AFAIK Lightspeed engine converts all the LINQ based syntax into their native API like QueryExpression and Query before execution. But I donot know how and what methods to call in order to achieve this. Any suggestions or solutions will be deeply appreciated as this is holding my work. ~ Sidharth |
|
|
You're correct that the LightSpeed engine converts LINQ expressions into core API QueryExpression and Query objects in order to execute them. However, the conversion engine isn't exposed: it's internal to the LINQ provider. There's not really a way to combine LINQ expressions with QueryExpressions. Your best solution is therefore to build your whole query as a LINQ expression. That is, instead of writing qe &= LambdaExpressionToQueryExpression(es), write something like: var andedExpression = Expression.AndAlso(existingLinqQuery, es); and pass the andedExpression to a LINQ Where clause. |
|
|
Hi Ivan, Well when I began on building this dynamic query, I initially started with LINQ expressions only. But in my scenario, I have to support multiple subqueries inside the where clause. Which, when i tried doing it with LINQ, I got stuck due to the limited support of LINQ based expressions. Earlier, I posted another question on the thread http://www.mindscape.co.nz/forums/Thread.aspx?ThreadID=2070 with an issue, which was relatively a minor problem but a big hurdle for continue using LINQ. Thus, I then resorted to the Base Lightspeed APIs. Is there a possibility you can expose some utility methods for converting the LambdaExpression to QueryExpression? Any more thoughts on how can I proceed. ~ Sidharth
|
|