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’m having some problems with the dynamic LINQ queries as LightSpeed doesn’t generate the “where” clause for the dynamically created LINQ queries . Could you please help me to resolve this using LINQ?
e.g:-
public List Find(string name, string email)
{
var customerQuery = from c in UnitOfWorkScope.Current.Customers
select c;
if (name != string.Empty)
{
customerQuery.Where(c => c.Name.StartsWith(name));
}
if (email != string.Empty)
{
customerQuery.Where(c => c.Email == email);
}
return customerQuery.ToList();
}
SQL Generated
......
Customer.Province,
Customer.UpdatedOn
FROM
Customer
WHERE
Customer.DeletedOn IS NULL
--> Time: 1 ms
Thanks.
|
|
|
Here is the html formated question....
I’m having some problems with the dynamic linq queries as LightSpeed doesn’t generate the “where” clause for the dynamically created linq queries . Could you please help me to resolve this? public List<Customer> Find(string name, string email){ var customerQuery = from c in UnitOfWorkScope.Current.Customers select c; if (name != string.Empty) { customerQuery.Where(c => c.Name.StartsWith(name)); }if (email != string.Empty) { customerQuery.Where(c => c.Email == email); } return customerQuery.ToList(); }SQL Generated…..Customer.Province, Customer.UpdatedOnFROM CustomerWHERE Customer.DeletedOn IS NULL --> Time: 1 ms Thanks |
|
|
Hi :) The statement "customerQuery.Where(....)" will return you a new instance of IQueryable<Customer> which contains the updated expression, however because you are not re-assigning this back to the customerQuery variable only the original expression you assigned is retained when you execute the query via .ToList(); Try inserting a customerQuery = <updated expression> and you should be sorted :)
Jeremy |
|