【发布时间】:2021-12-22 08:56:29
【问题描述】:
当我运行以下代码时:
List<Dag> result = session.CreateCriteria<Dag>()
.Add(Expression.Eq("Object_id", pObjectId))
.List<Dag>().ToList();
}
NHibernate 生成以下 SQL 查询:
exec sp_executesql N'SELECT this_. ... FROM schm.dag this_ WHERE this_.object_id = @p0',N'@p0 nvarchar(4000)',@p0=N'...'
这里的问题是 CAST 到 nvarchar(4000)。 hbm.xml 文件将object_id 列的映射定义为:
<property name="Object_id" type="String">
<column name="object_id" not-null="false" length="40" sql-type="varchar" />
</property>
那么为什么 NHibernate 会忽略映射文件中的信息而不使用varchar(40)?我找不到明确说明用于标准的属性类型的方法。我什至不确定我是否需要它,映射在 hbm.xml 文件中,为什么 NHibernate 不接受它?
这是在 .Net Framework 4.6(旧版应用程序)上运行的 NHibernate 4.1.4000。
【问题讨论】:
标签: c# nhibernate nhibernate-mapping hbm