Querying using Linq

  • Thread starter Thread starter Mike Collins
  • Start date Start date
M

Mike Collins

I want to allow users to search last names, using wildcards.

When I try to following in my web app:

//employees data was previously retrieved and stored in ViewState.
var filteredData = from p in employees.ToArray() select p;
filteredData = from c in employees
where SqlMethods.Like(c.Username, "%" + txtSearchCriteria.Text +
"%")
select c;

I get the following error:
Method Boolean Like cannot be used on the client it is only for translation
to SQL

Is there a way I can use Linq to get what I want and stay client side?
 
use standard c# string functions:

filteredData = from c in employees
where c.Username.ToUpper().IndexOf(txtSearchCriteria.Text.ToUpper) >= 0

you could easily implement a Like string extension that did this and have:

filteredData = from c in employees
where c.Username.Like (txtSearchCriteria.Text)


-- bruce (sqlwork.com)
 
Mike Collins said:
I want to allow users to search last names, using wildcards.

When I try to following in my web app:

//employees data was previously retrieved and stored in ViewState.
var filteredData = from p in employees.ToArray() select p;
filteredData = from c in employees
where SqlMethods.Like(c.Username, "%" + txtSearchCriteria.Text +
"%")
select c;

I get the following error:
Method Boolean Like cannot be used on the client it is only for
translation
to SQL

Is there a way I can use Linq to get what I want and stay client side?


Use .contains/startswith/endswith on the field to get a 'LIKE' equivalent

LS
 
Back
Top