Reference parent table alias in Fluent NHibernate ClassMap Formula?

对着背影说爱祢 提交于 2019-12-07 18:00:34

i do not understand the question completly. What is the problem/error with Formula presented?

Note: NHibernate will prepend all column names in the Formula without an alias with the alias of the table of the Entity containing the Forumula.

Note2: it is better to wrap the whole formula in parentesis (CASE ... END)

Update:

c.ID = ID will always evaluate to true

no it should not because the second ID has no prefix and will be given the prefix of the entitytable the formula is contained in. try log the sql generated to see.

example:

Map(u => u.RolesCount).Formula("(SELECT COUNT(*) FROM roles r WHERE r.user_id = id)");

//results in

SELECT
    user0_.Id as Id0_0_,
    (SELECT
        COUNT(*)
    FROM
        roles r
    WHERE
        r.user_id = user0_.id) as formula0_0_
FROM
    "User" user0_
WHERE
    user0_.Id=@p0;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!