含有连接的nHibernate公式

时间:2016-11-25 04:26:48

标签: nhibernate fluent-nhibernate fluent-nhibernate-mapping

当我指定以下公式时:

Map(x => x.PendingInviteCount)
    .Access
    .ReadOnly()
    .Formula("(SELECT COUNT(ui.UserInviteId) 
               FROM [UserInvite] ui JOIN [UserInviteOrganisation] uio 
               ON ui.UserInviteId = uio.UserInviteId 
               WHERE uio.OrganisationId = organisationId)");

生成的sql如下所示:

SELECT COUNT(ui.UserInviteId) 
FROM [UserInvite] ui 
JOIN [UserInviteOrganisation] organisati0_.uio on ui.UserInviteId = uio.UserInviteId 
WHERE uio.OrganisationId = organisati0_.organisationId

由于uio以organisatio0 _为前缀而失败。

是否可以创建包含JOIN的公式?

1 个答案:

答案 0 :(得分:3)

您应该使用AS关键字来设置表的别名。我不认为NHibernate会以它当前编写的方式接受它。