代码之家  ›  专栏  ›  技术社区  ›  Remotec

nHibernate CreateSqlQuery从位到布尔值的数据转换错误

  •  0
  • Remotec  · 技术社区  · 14 年前

    我在nHibernate和使用session.createSqlQuery(…)时有点懒惰,而不是用lambda来做全部的事情。不管怎样,structMe的意思是,将从(在本例中是mysql)db返回的某些类型转换为native.net tyes时似乎有问题。

    有问题的查询如下所示…

         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>();
    

    超级客户机数据库中的类型是位(1),在客户机对象中,类型是bool。

    收到的错误是:

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

    奇怪的是,这个转换无法完成。

    对任何想法都很好。

    谢谢。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Yoh Deadfall Omri    7 年前

    不用做任何羊羔肉(尽管它们很有趣!)如果 Client 是一个映射类,然后可以使用core-nhibernate方法 CreateCriteria<> . 这很简单:

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

    如果 顾客 没有映射,那么我将创建一个属性 SuperUser_Long 把它包起来 SuperUser