我想執行一個HQL插入語句來插入一些參數到我映射到實體的表中。插入HQL類型的命名參數插入HQL插入
以下是我目前的工作(這將引發異常):
Insert Into Entity1
(ForeignKey1, ForeignKey2, Date1, Date2)
SELECT this_.ForeignKey1,
cast(:param1 as int) as ForeignKeyValue2,
cast(:param2 as DateTime) as DateValue1,
cast(:param3 as DateTime) as DateValue2
FROM OtherEntity this_
WHERE ...
如果我離開了2日期字段插入的作品,所以我知道我靠近。我只需要弄清楚如何讓nhibernate將日期視爲日期。
例外:
insertion type [NHibernate.Type.Int32Type] and selection type
[NHibernate.Dialect.Function.CastFunction+LazyType] at position 1 are not compatible
[Insert Into Entity1
(ForeignKey1, ForeignKey2, Date1, Date2)
SELECT this_.ForeignKey1,
cast(:param1 as int) as ForeignKeyValue2,
cast(:param2 as DateTime) as DateValue1,
cast(:param3 as DateTime) as DateValue2
FROM OtherEntity this_
WHERE ...
如果任何人有做這樣的事情請隨時瀏覽體驗。此外,如果您知道如何使用HQL在日期時間上施放,也會有所幫助。 DBMS是MS SQL 2008 .:
SQL爲什麼投了?爲什麼不從NH呼叫中發送正確的參數類型? – 2012-04-23 22:17:09
我們可以看到設置參數的代碼嗎? – Rippo 2012-04-24 07:53:54