一直试图让以下查询工作几个小时,但我的想法已经用完了。任何人都可以找到我出错的地方。任何指针都非常赞赏。
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:参数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']
答案 0 :(得分:9)
"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查询中也使用命名参数。
答案 1 :(得分:2)
您应该删除query.ExecuteUpdate()
来电。
执行query.List()
就足以在会话上发出查询并返回结果集。