首先更新 nhibernate 代码中的计算列
update computed column in nhibernate code first
我首先使用 nhibernate 代码并且我有一个计算列。
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public virtual bool? IsInternal { get; set; }
当我尝试更新我的对象时,我收到一个错误:
无法修改列 "IsInternal",因为它是计算列或者是 UNION 运算符的结果。
计算列不需要任何更新(在大多数情况下,不需要持久化)。它总是在需要时即时计算。这就是您收到此错误的原因。
根据MSDN:
A computed column is a virtual column that is not physically stored in
the table, unless the column is marked PERSISTED. A computed column
expression can use data from other columns to calculate a value for
the column to which it belongs. You can specify an expression for a
computed column in in SQL Server 2016 by using SQL Server Management
Studio or Transact-SQL.
我应该在 属性 映射上将更新和插入设置为 false,它将解决这个问题
public virtual bool? IsInternal { get; set; }
Map.Property(p => p.IsInternal, u =>
{
u.Update(false);
u.Insert(false);
});
我首先使用 nhibernate 代码并且我有一个计算列。
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public virtual bool? IsInternal { get; set; }
当我尝试更新我的对象时,我收到一个错误: 无法修改列 "IsInternal",因为它是计算列或者是 UNION 运算符的结果。
计算列不需要任何更新(在大多数情况下,不需要持久化)。它总是在需要时即时计算。这就是您收到此错误的原因。
根据MSDN:
A computed column is a virtual column that is not physically stored in the table, unless the column is marked PERSISTED. A computed column expression can use data from other columns to calculate a value for the column to which it belongs. You can specify an expression for a computed column in in SQL Server 2016 by using SQL Server Management Studio or Transact-SQL.
我应该在 属性 映射上将更新和插入设置为 false,它将解决这个问题
public virtual bool? IsInternal { get; set; }
Map.Property(p => p.IsInternal, u =>
{
u.Update(false);
u.Insert(false);
});