带有标量函数的 NHibernate 公式
NHibernate formula with scalar function
我的对象中有一个使用公式映射的 属性,它是一个动态值,由我的数据库中定义的标量函数给出
这是我的映射:
<property name="StatusId" type="Int32" formula="(SELECT dbo.FN_GET_STATUS(ID))"/>
当我从会话工厂调用 GetById 函数时,这个 属性 给了我一个正确的值。但是,当我保存一个新创建的对象时,我没有得到 属性 的值。有什么办法可以修复它还是我做错了什么?
尝试使用内置设置generated="insert"
5.1.10. property
<property
name="propertyName" (1)
...
generated="never|insert|always" (8)
...(8) generated
(optional - defaults to never): Specifies that this property value is actually generated by the database. See the discussion of Section 5.5, “Generated Properties”.
5.5. Generated Properties
Generated properties are properties which have their values generated by the database. Typically, NHibernate applications needed to Refresh objects which contain any properties for which the database was generating values. Marking properties as generated, however, lets the application delegate this responsibility to NHibernate. Essentially, whenever NHibernate issues an SQL INSERT or UPDATE for an entity which has defined generated properties, it immediately issues a select afterwards to retrieve the generated values.
我的对象中有一个使用公式映射的 属性,它是一个动态值,由我的数据库中定义的标量函数给出
这是我的映射:
<property name="StatusId" type="Int32" formula="(SELECT dbo.FN_GET_STATUS(ID))"/>
当我从会话工厂调用 GetById 函数时,这个 属性 给了我一个正确的值。但是,当我保存一个新创建的对象时,我没有得到 属性 的值。有什么办法可以修复它还是我做错了什么?
尝试使用内置设置generated="insert"
5.1.10. property
<property
name="propertyName" (1)
...
generated="never|insert|always" (8)
...(8)
generated
(optional - defaults to never): Specifies that this property value is actually generated by the database. See the discussion of Section 5.5, “Generated Properties”.
5.5. Generated Properties
Generated properties are properties which have their values generated by the database. Typically, NHibernate applications needed to Refresh objects which contain any properties for which the database was generating values. Marking properties as generated, however, lets the application delegate this responsibility to NHibernate. Essentially, whenever NHibernate issues an SQL INSERT or UPDATE for an entity which has defined generated properties, it immediately issues a select afterwards to retrieve the generated values.