gpt4 book ai didi

sql - 通过 NHibernate 中的 CreateSQLQuery 返回类型化对象的列表

转载 作者:行者123 更新时间:2023-12-01 23:54:44 25 4
gpt4 key购买 nike

我已经尝试让以下查询工作几个小时了,但我已经没有想法了。谁能发现我哪里出错了。非常感谢任何指点。

CalEvents = (List<CalEvent>)session.CreateSQLQuery(@"
SELECT *
FROM dbo.tb_calendar_calEvents
INNER JOIN dbo.tb_calEvents
ON (dbo.tb_calendar_calEvents.calEventID = dbo.tb_calEvents.id)
WHERE dbo.tb_calendar_calEvents.calendarID = 'theCalID'"
)
.AddEntity(typeof(CalEvent))
.SetInt64("theCalID", cal.id);

错误:

Kanpeki.NUnit.CalUserTest.Should_return_logged_in_user: System.ArgumentException : Parameter theCalID does not exist as a named parameter in [SELECT * FROM dbo.tb_calendar_calEvents INNER JOIN dbo.tb_calEvents ON (dbo.tb_calendar_calEvents.calEventID = dbo.tb_calEvents.id) WHERE dbo.tb_calendar_calEvents.calendarID = 'theCalID']

最佳答案

"SELECT * FROM dbo.tb_calendar_calEvents INNER JOIN dbo.tb_calEvents ON (dbo.tb_calendar_calEvents.calEventID = dbo.tb_calEvents.id) WHERE dbo.tb_calendar_calEvents.calendarID = 'theCalID'"

应该是

"SELECT * FROM dbo.tb_calendar_calEvents INNER JOIN dbo.tb_calEvents ON (dbo.tb_calendar_calEvents.calEventID = dbo.tb_calEvents.id) WHERE dbo.tb_calendar_calEvents.calendarID = :theCalID"

= 'theCalID' 应写为 = :theCalId; :theCalId 是您在 native SQL 查询中使用命名参数的方式。

关于sql - 通过 NHibernate 中的 CreateSQLQuery 返回类型化对象的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/961888/

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