gpt4 book ai didi

nhibernate - 使用连接表的别名创建 SqlProjection

转载 作者:行者123 更新时间:2023-12-04 12:37:13 25 4
gpt4 key购买 nike

我有这种情况:

public class AnswerSet {
public virtual IList<Answer> Answers {set; get;}
}

session.CreateCriteria<AnswerSet>()
.CreateAlias( "Answers", "a" )
.SetProjection( Projections.ProjectionList()
.Add( Projections.GroupProperty( "TopicId" ), "TopicId" )
.Add( Projections.GroupProperty( "TopicName" ), "TopicName" )
.Add( Projections.SqlProjection( "count (case **{a}**.numerical_answer
when 1 then 1 when -1 then 1 else null end) as YesAnswers",
new[] { "YesAnswers" }, new IType[] { NHibernateUtil.Int32 } ), "YesAnswers" )

如何指定子集合别名?
{a}.numeric_answer 不工作和 {别名} 指的是答案集。

SQL等价物是
select
[as].topic_id as TopicId
, [as].topic_name as TopicName
, count (case [a].numerical_answer
when 1 then 1
when -1 then 1
else null
end) as YesAnswers
from answer_set [as] join answer [a] on [a].answer_set_id = [as].id

谢谢,
丹尼尔

最佳答案

numerical_answer不会出现在您的查询中的其他任何地方,您可以跳过表名,例如

"count (case numerical_answer when 1 then 1 when -1 then 1 else null end) as YesAnswers"

关于nhibernate - 使用连接表的别名创建 SqlProjection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5591378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com