Entity Framework 4.0 Use the default value for the database

I am using Entity Framework 4.0

Many of our tables have a RowID column used by the database administrator to track material. The NON NULLABLE column has a default value for the database that is displayed in the function.

The problem is that for the EDMX model, this property has a value for Entity, which complicates the construction of the object.

I read a lot of posts about setting up EDMX and SSDL files manually to make this work. This is not possible for our team.

Is there a better solution to this problem besides creating a NULLABLE column in the database? I don’t care about returning the value, I just want the database to be able to install it itself.

+6
entity-framework
source share
2 answers

You must set StoreGeneratedPattern = "Computed" directly in the SSDL (XML behind the model).

1 - Right Click Model

2 - Select "Open With" => Xml Editor

3 - Look at the display of one of the tables in the "Model Content" section

4 - Add the attribute StoreGeneratedPattern = "Calculated" to the RowID column

5 - Make a global replacement in your file so that each table has a RowID definition using StoreGeneratedPattern = "Computed"

Note: If you use the Model Update Wizard, you need to manually update the XML again. My recommendation: do not use the wizard or save the original and do not change the xml lines into a separate text file so that you can use them for global replacement after starting the wizard.

For more information, refer to this article: http://msdn.microsoft.com/en-us/library/dd296755(v=vs.90).aspx

+6
source share

If the RowID never needs to be read or written in the context of your application, it does not belong to your Entity model at all. Just remove it from your entity model using the constructor (right-click> Delete) and let it manage the database.

+2
source share

All Articles