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
|
Hi Guys, I would like to know if the following is possible: I want to create the query expression dynamically e.g.: QueryExpression exp1 = Entity.Attribute(someVar) == someValue; QueryExpression exp2 = Entity.Attribute(someOtherVar) > someOtherValue; QueryExpression exp3 = Entity.Attribute(Var1) > Value2; Once I've got these expessions I would like to add them toghter with either a && or || is this possible? Regards, Johan |
|
|
Hi Johan, Yes indeed you can use the && and || operators to join togethor parts of a query, these return a new QueryExpression instance. e.g. QueryExpression exp4 = exp1 && exp2 && exp3; You can also use this syntax when building up a query: e.g. QueryExpression exp5 = Entity.Attribute(Var1) > Value 2 && Entity.Attribute("Foo") == "Bar";
Jeremy |
|
|
Hi Jeremy, My problem is that I've got a list of expressions that I build up. Once I have the list I would like to join them. E.g. List<QueryExpression> experssions = new List<QueryExpression>(); expressions.Add( Entity.Attribute(Var1) > Value2 ); expressions.Add( Entity.Attribute("Foo") == "Bar" ); expressions.Add( Entity.Attribute("Bar") == "Foo" );
Foreach ( var exp in expressions ) x &= exp; Or something like this. |
|
|
If you just want to AND together a list of expressions then you can do this using the Aggregate operator: var combinedQuery = expressions.Aggregate((q1, q2) => q1 && q2); Similarly if you want to OR together a list of expressions. If you want to mix ANDs and ORs (e.g. (q1 && q2) || (q3 && q4)) then it's a bit trickier because you need to worry about which pairs to AND and which to OR, grouping/precedence, etc. If this is the case then have a look at http://www.mindscape.co.nz/forums/Post.aspx?ThreadID=1615&PostID=3609. |
|
|
Hi Ivan, Thanks for the response the Aggregate did the trick for me. |
|