NHibernate:帮助将 hql 查询转换为使用 criteria api
我有以下 hql 查询,我想切换到条件 API
select a.Id as Id, a.Name as Name, a.ActiveStatus as ActiveStatus,
dbo.GetActivityStartDate(a.Id) as StartDate,
dbo.GetActivityEndDate(a.Id) as EndDate,
coalesce(ac.Id,0) As CategoryId,
coalesce(ac.Name,'') As CategoryName
from Activity as a
left outer join a.Category as ac
显然,选择行上的初始属性很简单(Projections.Property);我的问题是..如何映射其余 4 个属性?
我有一个自定义方言,将 dbo.GetActivityStartDate 和 dbo.GetActivityEndDate 注册为标准 SQL 函数 - 因此已经处理了很多事情。
I have the following hql query which I'd like to switch over to the criteria API
select a.Id as Id, a.Name as Name, a.ActiveStatus as ActiveStatus,
dbo.GetActivityStartDate(a.Id) as StartDate,
dbo.GetActivityEndDate(a.Id) as EndDate,
coalesce(ac.Id,0) As CategoryId,
coalesce(ac.Name,'') As CategoryName
from Activity as a
left outer join a.Category as ac
Obviously the initial properties on the select line are trivial (Projections.Property); my question is..how do I map the remaining 4 properties?
I have a custom dialect that registers dbo.GetActivityStartDate
and dbo.GetActivityEndDate
as standard SQL functions - so that much is already taken care of.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以......结果我需要用我的自定义方言注册“ISNULL”函数;一旦我这样做了,使用 Projections.SqlFunction 以我需要的格式提取数据就变得很简单。
So...it turned out that I needed to register the "ISNULL" function with my custom dialect; once I did that, it was a simple matter of using the Projections.SqlFunction to extract the data in the format I required.