2

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.

1
  • Some examples? How do you insert values? Commented Jun 17, 2011 at 20:20

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.