如何在 Linq 中执行 SQL Like %? [英] How to do SQL Like % in Linq?

查看:39
本文介绍了如何在 Linq 中执行 SQL Like %?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SQL 过程,我想将其转换为 Linq:

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/%'

我最关心的是:

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

我有一列存储层次结构,例如/1/3/12/,所以我只使用 %/12/% 来搜索它.

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

我的问题是,Linq 或 .NET 与使用百分号的等价物是什么?

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

推荐答案

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

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

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

这篇关于如何在 Linq 中执行 SQL Like %?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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