You have taken the correct approach to creating a migration script. There is one thing you should known - Telerik Data Access
will not create a script that sets default values of the columns on the database side in a model-first scenario. Let me explain what are the two approaches one could take to assure an object is inserted with a default value for one or more of its properties:
1. The first one, is to set a default value in the constructor of newly initialized object. This way, when this object is persisted in the database by adding it to the context and eventually calling SaveChanges()
, the value of the defaulted property will in inserted in the database. This is logic used purely on the client-side and does not involve any database schema specifics.
2. The second approach is useful when working with columns that have default values being set by the database server. In such cases you could use the HasDefaultValue
method in a persistent type mapping to instruct Telerik Data Access
to omit a property from its insert statements allowing the database server to populate that column with its database set default value. It is important to note that creating a database out of such a model will not result in columns with default values on the database side
. This means that you will have to prepare a script yourself altering those columns to have a default value.
Please refer to this documentation article
that addresses both approaches.
I hope this is helpful. Do let us know if you have any further questions.
Check out the latest announcement
about Telerik Data Access vNext as a powerful framework
able to solve core development problems.