且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 NHibernate 命名查询中使用未映射的类

更新时间:2022-02-12 09:15:55

为了解决这个问题,我最终使用了 TupleToPropertyResultTransformer 并提供了属性值列表.对此有一些限制,主要的限制是 SQL 查询必须以与您向 TupleToPropertyResultTransformer 构造函数提供属性相同的顺序返回结果.

To solve this, I ended up using the TupleToPropertyResultTransformer and providing the list of property values. There are a few limitations to this, the main one being that the SQL query must return the results in the same order as you provide your properties to the TupleToPropertyResultTransformer constructor.

此外,属性类型是推断出来的,所以你需要小心十进制列只返回整数值等.除此之外,使用 TupleToPropertyResultTransformer 提供了一种相当简单的方法来使用 SQL 查询返回对象集合,而无需显式映射NHibernate 中的对象.

Also the property types are inferred so you need to be careful with decimal columns returning only integer values etc. Apart from that using the TupleToPropertyResultTransformer provided a reasonably easy way to use an SQL query to return a collection of objects without explicitly mapping the objects within NHibernate.