集合上的NHibernate多态查询 [英] NHibernate Polymorphic Query on a Collection

查看:130
本文介绍了集合上的NHibernate多态查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在NHibernate中编写查询.我不太在乎是否使用Criteria API或HQL,只是不知道如何编写查询.

I'm trying to write a query in NHibernate. I don't really care if I use the Criteria API or HQL, I just can't figure out how to write the query.

这是我的模特:

public class LogEntry { public DateTime TimeCreated { get; set; } }
public class Note : LogEntry { public string Content { get; set; } }

public class Workflow { public IList<LogEntry> Log { get; set; } }

我希望查询返回所有包含注释的工作流,该注释在注释的内容中带有特定的单词.

I want the query to return all Workflows that which contain a Note with specific words in the Content of the note.

在伪SQL中,我会这样写:

In pseudo-SQL, I'd write this like:

select w.*
from Workflow w
join w.Log l where l is class:Note
where (Note)l.Content like '%keyword%'

推荐答案

我不确定Criteria API,但是即使搜索仅存在于特定子项中的属性,HQL似乎也能很好地处理多态查询-班级.我希望以下方法能起作用:

I'm not sure about the Criteria API, but HQL seems to handle polymorphic queries quite well, even when searching on a property that only exists in a specific sub-class. I would expect the following to work:

from Workflow w join w.Log l where l.class = Note and l.Content like '%keyword%'

这篇关于集合上的NHibernate多态查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆