NHibernate - ICriteria 帮助
我正在尝试将以下 SQL 查询转换为 NHibernate 中的 ICriteria。
SELECT DISTINCT m.typeId, t.typeName
FROM Models m, Types t
WHERE m.qualifier=? AND m.typeId IS NOT NULL AND m.typeId = t.typeId
它们都在 NHibernate 中映射到名为 Models 和 ModelType 的类中。 ICriteria.List 应返回 ModelType 类型的列表。
谢谢
I'm trying to convert the following SQL query to an ICriteria in NHibernate.
SELECT DISTINCT m.typeId, t.typeName
FROM Models m, Types t
WHERE m.qualifier=? AND m.typeId IS NOT NULL AND m.typeId = t.typeId
These are both mapped in NHibernate in classes called Models and ModelType. The ICriteria.List should return a list of type ModelType.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有好消息也有坏消息。您可以创建一个将返回模型类型列表的条件。但是,它们不会受到会话管理。原因是,不同的查询只能返回投影,并且投影始终不受管理。
下面的查询将生成与上面类似的查询,因为它在两个实体之间进行内部联接,并根据这两列返回一个不同的集合。结果转换器应设置为生成某种可以通过属性设置的类型。您可能可以返回 ModelType 列表,但只需知道它们不会由会话管理。
There are good news and bad news. You can create a criteria that will return a list of ModelTypes. However, they will not be session managed. The reason is, that a distinct query can only return a projection and projections are always unmanaged.
The query below will generate a similar query to the above as it does an inner join between the two entities and returns a distinct set based on those 2 columns. The result transformer should be set to generate some type that can be set via properties. You can probably return a list of ModelTypes, but just know that they won't be managed by the session.