dannikoti
dannikoti

Reputation: 231

SQL Server default value does not appeared as entity default value

Default value from SQL Server table's column does not appear in entity.

Is it normal behavior?

I have tried to figure it out but with no result. Thanks for any help.

Upvotes: 2

Views: 717

Answers (3)

Rajesh
Rajesh

Reputation: 2502

you can tell entity framework that database will take care of that property by editing that property in SSDL of the edmx file.

Initially

<Property Name="CompanyName" Type="nvarchar" Nullable="false" MaxLength="40" />

we have change it to

<Property Name="CompanyName" Type="nvarchar" Nullable="false" MaxLength="40" StoreGeneratedPattern="Computed" />

by setting storeGeneratedPattern="Computed" we can tell to EF that the property value will be inserted by DB.

For Editing SSDL

  1. Right click the edmx file, open with XML(text) Editor.

2.Ctrl+F name of the property and just change that property

Upvotes: 1

Joel C
Joel C

Reputation: 5567

Entity Framework provides an explicit value for each property. In SQL you can write a query that inserts a value into [Field1] and leave [Field2] and [Field3] blank, and they will use the database default. But since Entity Framework generates the query based on the properties defined on the entity, all columns will always be given a value, so if you want to provide a default value, it will need to be set in the designer, I don't think it gets automatically picked up when the entity model is created.

Upvotes: 0

therealmitchconnors
therealmitchconnors

Reputation: 2760

Entities have their own default values set in the designer. Right click your entity and select properties to see the default value.

Upvotes: 2

Related Questions