我正在尝试执行 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 ...
如果有人有做这种事情的经验,请随时提供帮助。此外,如果您知道如何在 DateTimes 上使用 HQL 转换,那也会有所帮助。DBMS 是 MS SQL 2008。: