views:

41

answers:

1

I might be missing something, but a SQL Server 2008 R2 database as generated by Entity Framework 4 is missing the default values I configured via the EF designer.

Any ideas what I could be doing wrong?

+1  A: 

The reason for that is because the default values that you can set in the conceptual model and the database defaults are completely unrelated.
Let's consider a typical situation where you already have a database that has default values set on columns, by the same token, that default will NOT get picked up in the store schema or by the entity itself.

Therefore, if you define a default value for a property of an entity in a model that will be used to generate a database schema, it’s important to be aware that none of the default values you define for an entity’s property will get pushed to the database.

However, it's worth mentioning that the default EntityObject T4 code generation template and the default POCO Entities template will both set that property’s default value in the generated class.

You can verify this by take a closer look at yourModelName.edmx.sql file that has been generated by VS2010 once you click on "Generate Database From Model...". As you can see, there is NO such a thing like this in it:
ADD CONSTRAINT DEFAULT "Default Value" FOR YourColumnName

Morteza Manavi
Thank you for the concise answer. Makes perfect sense.
Shaun