我先使用nhibernate代碼並且我有一個計算列。更新nhibernate代碼中的計算列第一個
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public virtual bool? IsInternal { get; set; }
當我試圖更新我的目標,我收到了一個錯誤: 列「IsInternal」不能被修改,因爲它要麼是一個計算列,或者是UNION運算符的結果。
我先使用nhibernate代碼並且我有一個計算列。更新nhibernate代碼中的計算列第一個
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public virtual bool? IsInternal { get; set; }
當我試圖更新我的目標,我收到了一個錯誤: 列「IsInternal」不能被修改,因爲它要麼是一個計算列,或者是UNION運算符的結果。
我應該設置更新和插入假的屬性映射,它會解決這個問題
public virtual bool? IsInternal { get; set; }
Map.Property(p => p.IsInternal, u =>
{
u.Update(false);
u.Insert(false);
});
計算列不需要任何更新(在大多數情況下,不保留)。它總是在需要時即時計算。這就是你得到這個錯誤的原因。
根據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.
我沒有更新該列。它會自動更新 –
其計算列,你爲什麼要手動更新呢?它就像有一個返回'2 + 4'值的列並試圖將其設置爲'10',這沒有任何意義......我不認爲它應該有一個'set'方法,但我習慣於使用EF ... –
我沒有更新該列。它會自動更新。如果我沒有設置它不會顯示該屬性在我的用戶界面中的值 –