NHibernate:帮助将 hql 查询转换为使用 criteria api

发布于 2024-09-11 00:20:21 字数 503 浏览 3 评论 0原文

我有以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪眸﹌ 2024-09-18 00:20:21

所以......结果我需要用我的自定义方言注册“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文