本文介绍了nHibernate 3.0.0.4000在查询中对bool的处理方式不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将nHibernate从版本3.0.0.1002更新到了3.0.0.4000.一旦我这样做,我的许多查询就会开始失败.一个这样的查询是这样的:

I just updated nHibernate from version 3.0.0.1002 to 3.0.0.4000. As soon as I did that many of my queries started failing. One such query is this:

var items = (from b in session.Query<InvoiceDetail>() 
                            where b.Customer == AddressedToCustomer && b.IsCreditNote == !addInvoices 
                            orderby b.DueDate , b.InvoiceNumber 
                            select b).ToList(); 

在3.0.0.1002中生成的SQL:

SQL Generated in 3.0.0.1002:

在3.0.0.4000中生成的SQL:

SQL Generated in 3.0.0.4000:

我正在使用约定将布尔值转换为整数(true = 1,false = 0).以前的版本正在进行此转换,而新版本则没有. bool在较新的版本中将转换为字符串,但应根据约定将其转换为int.

I am using a convention to convert bools into ints (true=1, false=0). The previous version is doing this conversion, the newer version isn't. The bool is converted to a string in the newer version, but it should be converted to int according to the convention.

从生成的SQL:
!addInvoices"作为字符串在sql查询中传递,并在先前版本中以int形式传递:
3.0.0.1002:@p1 = True [Type:Int32(0)]
3.0.0.4000:@ p1 ='True'[Type:字符串(0)]

From generated SQL:
"!addInvoices" is passed as a string in the sql query and int in the previous version:
3.0.0.1002: @p1 = True [Type: Int32 (0)]
3.0.0.4000: @p1 = 'True' [Type: String (0)]

还将IsCreditNote数据库字段在新版本中与"true"和"false"进行比较,并在先前版本中将其与1和0进行比较.

Also, the IsCreditNote database field is compared to 'true' and 'false' in the new version, and with 1 and 0 in the previous version.

第二,即使我删除了约定,这也是3.0.0.4000中两个不同命令的输出:
插入:

Secondly, even if I remove the convention, this is the output for two different commands in 3.0.0.4000:
Insert:

更新:

在插入"中,传递的参数是布尔值(@ p6),在选择"中,参数是字符串(@ p1).

In Inserts, the passed parameter is a Boolean (@p6), and in Selects, the parameter is a String (@p1).

问题是,我在nHibernate JIRA上将此问题发布为问题(实际上大部分是是从该问题线程复制的),但Patrick Earl作为非问题而关闭了该问题.他说这是标准行为.

The thing is, I posted this as an issue on nHibernate JIRA (actually most of this is copied from that issue thread), but Patrick Earl closed the issue as a non-issue. He said this is the standard behavior.

nHibernate之前的所有版本均运行正常.只有这一行为有所不同.有人可以评论这确实是一个错误,还是Patrick正确,我需要在数据库中解决此问题?

All the versions of nHibernate before this version behaved correctly. Only this one behaves differently. Can anybody comment is this really a bug, or is Patrick correct and I need to workaround this problem in my database?


我的数据库是SQLite,正在使用Fluent nHibernate.


My database is SQLite and I am using Fluent nHibernate.

推荐答案

Phill是正确的. Query/LINQ提供程序有问题.

Phill is right. The Query/LINQ provider has issues.

此Criteria/QueryOver API可以完美运行:

This Criteria/QueryOver API works perfectly:

var items = session.QueryOver<InvoiceDetail>()
        .Where(i => i.Customer == AddressedToCustomer)
        .And(i => i.IsCreditNote != addInvoices)
        .OrderBy(i => i.DueDate).Asc
        .ThenBy(i => i.InvoiceNumber).Asc
        .List();

更令人惊讶的是,提供程序的开发人员只是将问题/错误视为非问题而关闭,甚至没有适当地对其进行检查.为了确保,我打算将所有Query<>调用替换为QueryOver<>调用.对于像nHibernate这样的项目,确实很可惜,特别是考虑到喜欢linq的像我这样的开发人员.

And even more surprising is that the developers of the provider just close issues/bugs as non-issues without even looking into them properly. I am planning to replace all Query<> calls to QueryOver<> calls just to be sure. For a project like nHibernate, this is indeed a pity specially considering developers like me who love linq.

这篇关于nHibernate 3.0.0.4000在查询中对bool的处理方式不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 19:02