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 have a search page where the user selectively inserts fields to search on. if none of them are filled in then I want to get all the rows. What I would like to have is: QueryExpression q = true; // <--- **** HOW DO I DO THIS? if(input1 has text) q = q && Entity.Attribute("Name").Like("%" + input1.Text + "%"); if(input2 has text) q = q && Entity.Attribute("Color") == Int32.Parse(input2.Text); Person p = uow.Find<Person>(q);
Is this the right way of doing this? Other times I'd like to start with false (dont return anything) then build up depending on input parameters (using the || (OR) operator) |
|
|
The easiest way to do this is to compare Id against a never-used value e.g. QueryExpression q = (Entity.Attribute("Id") != -1); // always true To start out false of course just flip the Id comparison. This is not maximally efficient because the vacuous Id comparison does get included in the query but with a good index on the Id column the performance impact should be negligible. |
|