Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update computed column in nhibernate code first

I'm using nhibernate code first And I have a computed column.

[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public virtual bool? IsInternal { get; set; }

when I'm trying update my object, I received an error: The column "IsInternal" cannot be modified because it is either a computed column or is the result of a UNION operator.

like image 481
Fereshteh Rabet Avatar asked Jan 25 '26 00:01

Fereshteh Rabet


2 Answers

I should set update and insert to false on property mapping and It will solve this problem

public virtual bool? IsInternal { get; set; }

Map.Property(p => p.IsInternal, u =>
            {
                u.Update(false);
                u.Insert(false);
            });
like image 103
Fereshteh Rabet Avatar answered Jan 27 '26 15:01

Fereshteh Rabet


A computed column doesn't need any update (in most situations, not persisted). It always calculated on the fly, when it is needed. This is why you get this error.

According to 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.

like image 44
Christos Avatar answered Jan 27 '26 14:01

Christos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!