Querying using Linq

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?
 
B

bruce barker

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)
 
L

Lloyd Sheen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Linq to entites 13
Linq May CTP 2006 1
Linq 5
LINQ & SCOPE_IDENTITY 4
effective linq delete 5
recreate linq ToArray format 0
LINQ - Need Advice 1
linq to DataTable issues 0

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top