喜欢不逃避NHibernate的特殊人物

时间:2023-01-08 10:18:11

I have a problem with NHibernate LINQ contains method, because I want to escape special characters in the string for example if I type:

我有NHibernate LINQ包含方法的问题,因为我想要转义字符串中的特殊字符,例如,如果我键入:

lel%lel

I want to find exactly

我想找到确切的

lel%lel but not lel4325234534lel

To find values I use following methods:

要查找值,我使用以下方法:

tabArray = _session.Query<Tab>()
                    .Where(x => x.attr.Contains(query))
                    .ToArray();

I also try using likeexpression but it also didn't help.

我也尝试使用likeexpression,但它也没有帮助。

1 个解决方案

#1


I would say, that this should be up to us (our code) not NHibernate. We can use this:

我想说,这应该取决于我们(我们的代码)而不是NHibernate。我们可以用这个:

How do I escape a percentage sign in T-SQL?

如何在T-SQL中转义百分号?

i.e. replace any % in C# with [%]

即用[%]替换C#中的任何%

lel[%]lel 

And this would return what expected

这将回归预期

.Where(x => x.attr.Contains(query)) // query == "lel[%]lel"

#1


I would say, that this should be up to us (our code) not NHibernate. We can use this:

我想说,这应该取决于我们(我们的代码)而不是NHibernate。我们可以用这个:

How do I escape a percentage sign in T-SQL?

如何在T-SQL中转义百分号?

i.e. replace any % in C# with [%]

即用[%]替换C#中的任何%

lel[%]lel 

And this would return what expected

这将回归预期

.Where(x => x.attr.Contains(query)) // query == "lel[%]lel"