Compiled Linq & String.Contains

Posted by sharru on Stack Overflow See other posts from Stack Overflow or by sharru
Published on 2010-03-24T12:37:50Z Indexed on 2010/03/24 12:53 UTC
Read the original article Hit count: 1060

Filed under:
|
|

i'm using linq-to-sql and i'm use complied linq for better performance.

I have a users table with a INT field called "LookingFor" that can have the following values.1,2,3,12,123,13,23.

I wrote a query to return the users based on the "lookingFor" column i want to return all users that contains the "lookingFor" value (not only those equal to it).

In example if user.LookingFor = 12 , and query paramter is 1 this user should be selected.

private static Func<NeDataContext, int, IQueryable<int>>
      MainSearchQuery = CompiledQuery.Compile((NeDataContext db, int lookingFor) =>
         (from u in db.Users
          where (lookingFor == -1 ? true : u.LookingFor.ToString().Contains(lookingFor)                         
    select u.username);

This WORKS on non complied linq but throws error when using complied. How do i fix it to work using complied linq?

I get this error:

Only arguments that can be evaluated on the client are supported for the String.Contains method.

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about .NET