Fereshteh Rabet
Fereshteh Rabet

Reputation: 201

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.

Upvotes: 3

Views: 1161

Answers (2)

Fereshteh Rabet
Fereshteh Rabet

Reputation: 201

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);
            });

Upvotes: 2

Christos
Christos

Reputation: 53958

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.

Upvotes: 1

Related Questions