我有一个基本的nHibernate,我正在尝试使用公式映射属性:
CREATE FUNCTION [dbo].[IsValueApprovalRequired]
(
-- Add the parameters for the function here
@ValueApprovalID BigInt
)
RETURNS Bit
AS
BEGIN
return CAST(1 as bit)
END
我的类定义非常简单,我试图将公式映射到类中:
[Class(Table="MyTable")]
public class MyClass
{
private long _id;
/// <summary>
/// A unique identifier for the object
/// </summary>
[Id(0, Name = "ID", Column = "ValueApproval_ID")]
[Generator(1, Class = "identity")]
public override long ID
{
get
{
return _id;
}
set
{
this._id = value;
}
}
[NHibernate.Mapping.Attributes.Formula(Content = "(SELECT dbo.IsValueApprovalRequired(ID))")]
private bool _isValueApprovalRequired;
/// <summary>
/// returns if this approval is considered required.
/// </summary>
public virtual bool IsValueApprovalRequired
{
get { return _isValueApprovalRequired; }
}
}
正在加载类,但是未填充映射到公式的变量。
有谁知道为什么这不起作用?我看了sql请求,标量不在给定的select语句中。
提前感谢您的帮助!
答案 0 :(得分:0)
我们也有这个问题。
您需要修改代码并添加PropertyAttribute:
[Property, Formula(Content = "(SELECT dbo.IsValueApprovalRequired(ID))")]