问题描述
我有 linq to nhibernate 查询:
I've got linq to nhibernate query:
var listka =
from i in FakturyZakupu.Queryable
where String.Compare(i.REJESTRY.REJ_KOD,sbWartoscBetween1.ToString()) >= 0
&& String.Compare(i.REJESTRY.REJ_KOD,sbWartoscBetween2.ToString()) <= 0
select i;
lista = listka.ToList();
而且它编译得很好,但是如果我使用它,就会抛出异常:
And it is compiling very well, but if I use it, the exception is thrown:
NotSupportedException int32 CompareTo(System.String, System.String)
如何在两个值之间使用 linq 查询字符串值.就像在 SQL 中:select * from table where id 介于 a 和 b 之间?
How could I take using linq query string values between two values. Like in SQL:select * from table where id between a and b ?
推荐答案
NHibernate 的 Linq provider 非常可扩展.您可以扩展它以允许任何表达式,只要您可以在 HQL 中编写该表达式,因为 NHibernate 的 Linq 正在转换为 HQL.
NHibernate's Linq provider is very extendable. You could extend it to allow any expression, as long as you can write that expression in HQL, since NHibernate's Linq is converting to HQL.
因此,如果您为 between 编写扩展,您的代码可能如下所示:
So, if you write the extension for Between, your code could look like this:
var listka =
from i in FakturyZakupu.Queryable
where i.REJESTRY.REJ_KOD.Between(sbWartoscBetween1, sbWartoscBetween2)
select i;
lista = listka.ToList();
以下是一些帮助您入门的链接:
Here are some links to get you started:
- Fabio Maulo 的 NHibernate Linq 提供程序扩展
- Linq 到 NHibernate:字符串.等于 StringComparison 选项
- NHibernate 3 - 将 Linq 提供程序扩展到修复一些 System.NotSupportedException
- NHibernate - 自定义 Linq 提供程序调用用户定义的 SQL 函数
- Linq 到 NHibernate 扩展一个>
- 为 NHibernate 3 Linq Provider 创建 In 和 NotIn 扩展方法
- 为正则表达式扩展 NHibernate-LINQ-匹配
- NHibernate 的自定义 LINQ 扩展
这篇关于linq to nhibernate compareto 不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!