我在SQL中有一个程序,我试图变成Linq:
SELECT O.Id, O.Name as Organization
FROM Organizations O
JOIN OrganizationsHierarchy OH ON O.Id=OH.OrganizationsId
where OH.Hierarchy like '%/12/%'
Run Code Online (Sandbox Code Playgroud)
我最关心的是:
where OH.Hierarchy like '%/12/%'
Run Code Online (Sandbox Code Playgroud)
我有一个存储层的列,例如/ 1/3/12,所以我只使用%/ 12 /%来搜索它.
我的问题是,Linq或.NET相当于使用百分号?
我正在使用Linq-to-SQL,我使用编译的Linq来获得更好的性能.
我有一个INT名为"LookingFor"字段的用户表,它可以具有以下值:1,2,3,12,123,13,23.
我写了一个查询,根据"lookingFor"列返回用户,我想返回包含"lookingFor"值的所有用户(不仅仅是那些等于它的用户).
在示例if user.LookingFor = 12和query参数中1,应该选择此用户.
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);
Run Code Online (Sandbox Code Playgroud)
这个工作在非编译的linq上,但在使用编译时抛出错误.如何使用编译的Linq修复它?
我收到此错误:
String.Contains方法仅支持可在客户端上计算的参数.