What does the data annotation [DatabaseGenerated (DatabaseGenerationOption.Computed)] do?

I'm trying to figure out what

[DatabaseGenerated(DatabaseGenerationOption.Computed)] 

DataAnnotation actually does. However, I cannot find any information using Google search or MSDN search. Somebody knows?

+8
c # entity-framework entity-framework-4 code-first
source share
2 answers

A computed column is a table column that is not updatable, but instead is based on other data in a row.

This is similar to a view, but it is lighter and can be PERSISTED without having to create an indexed view.

For example, you might have a computed column to combine two numbers like this (in T-SQL):

 CREATE TABLE [Foo] ( [FooId] int NOT NULL IDENTITY, CONSTRAINT [Foo_PK] PRIMARY KEY ([FooId]), [ItemA] int, [ItemB] int, [Sum] AS ([ItemA] + [ItemB]) ) 

Entity Framework needs to be aware of these columns so that it does not try to issue an Update statement that will attempt to change the value of this column.

+9
source share

This attribute is used in the first entity of the Entity Framework, in which it determines how the value is generated. DatabaseGenerationOptions is an enumeration of Identity , Computed , None , where Identity mapped to an identity column, Computed is a computed column.

+3
source share

All Articles