简体   繁体   English

NHibernate CreateSQLQuery数据从位转换为布尔错误

[英]NHibernate CreateSQLQuery data conversion from bit to boolean error

Im being a bit lazy in NHibernate and using Session.CreateSqlQuery(...) instead of doing the whole thing with Lambda's. 我对NHibernate有点懒,并且使用Session.CreateSqlQuery(...)而不是用Lambda来完成整个工作。 Anyway what struct me is that there seems to be a problem converting some of the types returned from (in this case the MySQL) DB into native .Net tyes. 无论如何,让我感到不适的是,将某些(从本例中的MySQL)数据库返回的类型转换为本地.Net tyes似乎存在问题。

The query in question looks like this.... 有问题的查询如下所示。

     IList<Client> allocatableClients =
                    Session.CreateSQLQuery(
                      "select clients.id as Id, clients.name as Name, clients.customercode as CustomerCode, clients.superclient as SuperClient, clients.clienttypeid as ClientType " +
...
...
.SetResultTransformer(new NHibernate.Transform.AliasToBeanResultTransformer(typeof(Client))).List<Client>();

The type in the database of SuperClient is a bit(1) and in the Client object the type is a bool. SuperClient数据库中的类型为bit(1),在Client对象中,类型为bool。

The error received is: 收到的错误是:

System.ArgumentException: Object of type 'System.UInt64' cannot be converted to type 'System.Boolean'.

It seems strange that this conversion cannot be completed. 无法完成此转换似乎很奇怪。

Would be greatful for any ideas. 对于任何想法都会很棒。

Thanks. 谢谢。

No need to do any lambdas (even though they are fun!). 无需做任何lambda(即使它们很有趣!)。 If Client is a mapped class then you can use the core NHibernate method CreateCriteria<> . 如果Client是映射类,则可以使用核心NHibernate方法CreateCriteria<> It is very simple: 这很简单:

session
    .CreateCriteria<Client>()
    .List<Client>();

If Client isn't mapped then I would create a property SuperUser_Long and wrap it with SuperUser 如果未映射Client则我将创建一个属性SuperUser_Long并用SuperUser包装

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM