我使用LINQ到SQL和我使用编译的LINQ获得更好的性能。
I'm using Linq-to-SQL and I use compiled Linq for better performance.
我有用户表与 INT
字段称为LookingFor,可以有以下值: 1,2,3,12,123,13 23
。
I have users table with a INT
field called "LookingFor" that can have the following values: 1,2,3,12,123,13,23
.
我写了一个查询,返回基于lookingFor列中的用户,我想返回包含lookingFor值的所有用户(不仅是相等的话)。
I wrote a query to return the users based on the "lookingFor" column and I want to return all users that contain the "lookingFor" value (not only those equal to it).
在例如,如果 user.LookingFor = 12
,和查询放慢参数是 1
,并且这个用户应选择
In example if user.LookingFor = 12
, and query paramter is 1
, and 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);
这适用于非编译过LINQ,但会抛出错误使用编译时。 它使用如何解决编译的LINQ?
This WORKS on non complied linq but throws error when using compiled. How do I fix it using compiled Linq?
我得到这个错误:
这可以在客户端上进行评估的仅论据支持的String.Contains方法。
Only arguments that can be evaluated on the client are supported for the String.Contains method.
我面临同样的问题。我现在只有一个办法解决这个问题的方法进行管理。而不是使用
I'm facing the same problem. I have managed for now just one workaround for this problem. Instead of using
u.LookingFor.ToString().Contains(lookingFor)
我用
u.LookingFor.ToString().IndexOf(lookingFor) >= 0