Nhibernate Linq&;操作员注册表函数Firebird

Nhibernate Linq&;操作员注册表函数Firebird,nhibernate,firebird,linq-to-nhibernate,Nhibernate,Firebird,Linq To Nhibernate,我将NHibernate与Firebird一起使用,并希望为Firebird函数bin\u和(a,b) 大概是这样的: var result = customers.Where(c => (c.StatusValue & 3) > 0); 上述查询将产生如下结果: select * from customers where (StatusValue & 3) > 0 在Firebird中无效,结果应为: select * from customers whe

我将NHibernate与Firebird一起使用,并希望为Firebird函数
bin\u和(a,b)

大概是这样的:

var result = customers.Where(c => (c.StatusValue & 3) > 0);
上述查询将产生如下结果:

select * from customers where (StatusValue & 3) > 0
在Firebird中无效,结果应为:

select * from customers where bin_and(StatusValue,3) > 0
是否有可能覆盖此翻译结果

更新

通过声明函数,这是可能的:

var result=customers.Where(c=>BinAnd(c.StatusValue,3)>0)

这是可行的,但我正在寻找一种更通用的方法,使用“&”或“|”运算符

更新:

@费德里克:

我自己写的方言课是这样的:

 public class MyFirebirdDialect: FirebirdDialect    {
       public MyFirebirdDialect()
       {
          // Bitwise operations
          RegisterFunction("band", new BitwiseFunctionOperation("bin_and"));
          RegisterFunction("bor", new BitwiseFunctionOperation("bin_or"));
          RegisterFunction("bxor", new BitwiseFunctionOperation("bin_xor"));
          RegisterFunction("bnot", new BitwiseFunctionOperation("bin_not"));
       }    
}
我还必须导入BitwiseFunctionOperation.cs

如果我调试代码,我会看到这个类被用作方言,我会看到键“band”有一个自定义函数,它有一个值“bin_and”,但类似这样的查询

 var result = customers.Where(c => (c.StatusValue & 3) > 0);
最终生成如下sql:

 select * from customers where (StatusValue & 3) > 0

我认为linq解析器不属于它的一部分…

您使用的是适当的方言吗
FirebirdDialect
在HQL中正确定义了位和(并将
&
ExpressionType.and
)翻译为

如果您使用的是旧的NHibernate版本,可能需要升级

NHibernate 4.1中添加了Firebird逐位运算符

您可以尝试使用从
FirebirdDialect
派生的自定义方言,并在自定义方言构造函数中注册上述链接中所示的附加函数,从而在项目中对其进行反向移植


但这是行不通的,因为它需要NHibernate内部的其他一些,在NHibernate 4.1之前是不可用的。也许通过修补NHibernate 3.4源代码的本地副本,您可以成功地做到这一点。

Ahh Frédéric,多么令人惊讶:-)我正在使用NHibernate 3.4,这是支持.Net 3.5的最后一个版本。客户的结果。其中(c=>(c.StatusValue&3)>0)不会在所需的“bin\u”中转换,请参见我的编辑。当然,最好升级应用程序框架。3.5的支持即将结束。自内置Linq提供程序中的NHibernate v3.0以来,所有必需的Linq代码似乎都在那里。您是否使用HQL
band()
检查过查询是否生成了足够的SQL?我明天会检查并给出响应,确定我下载了源代码,并且从未调用过“HqlGeneratorExpressionTreeVisitor”。hql命令既不起作用,它总是在我的sql中使用“&”……嗯,在NHibernate 4.1中似乎也有将按位操作重新定义为函数的能力。这就是HQL也不起作用的原因。
 select * from customers where (StatusValue & 3) > 0