怎么办SQL类似%Linq中? [英] How to do SQL Like % in Linq?

查看:152
本文介绍了怎么办SQL类似%Linq中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SQL一个过程,我想变成的Linq:

  SELECT O.Id,O.Name作为组织
从组织Ø
JOIN OrganizationsHierarchy OH ON O.Id = OH.OrganizationsId
其中,OH.Hierarchy像'%/ 12 /%
 

我最关心的是该生产线是:

 其中OH.Hierarchy像'%/ 12 /%
 

我有一个存储层级状/ 1/3/12 /譬如,所以我只是用%/ 12 /%至搜索。列

我的问题是,什么是LINQ的或.NET等同于使用百分号?

解决方案

 。凡(OH => oh.Hierarchy.Contains(/ 12 /))
 

您也可以使用 .StartsWith() .EndsWith()

I have a procedure in SQL that I am trying to turn into Linq:

SELECT O.Id, O.Name as Organization
FROM Organizations O
JOIN OrganizationsHierarchy OH ON O.Id=OH.OrganizationsId
where OH.Hierarchy like '%/12/%'

The line I am most concerned with is:

where OH.Hierarchy like '%/12/%'

I have a column that stores the hierarchy like /1/3/12/ for example so I just use %/12/% to search for it.

My question is, what is the Linq or .NET equivalent to using the percent sign?

解决方案

.Where(oh => oh.Hierarchy.Contains("/12/"))

You can also use .StartsWith() or .EndsWith().

这篇关于怎么办SQL类似%Linq中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆