linq to nhibernate compareto 不支持 [英] linq to nhibernate compareto not supported

查看:23
本文介绍了linq to nhibernate compareto 不支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 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)

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:

这篇关于linq to nhibernate compareto 不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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