when doing database planning, it is common to plan some system fields, that is, the database itself assigns default values to this field, and the creation of a new Create Time (createdate) field is often designed. If you want to have a default value and have the. NET program not specify a value when adding information to the database, then you need to add a databasegenerated attribute (Attribute) to your property. And pass in the databbasegeneratedoption.computed parameter to the Databasegenerated property. Remember to refer to the namespace System.ComponentModel.DataAnnotations in advance when calling the Databasegenerated property, System.ComponentModel.DataAnnotations.Schema: The concrete implementation is as follows.usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.ComponentModel.DataAnnotations;usingSystem.ComponentModel.DataAnnotations.Schema;namespaceartech.vm.models{ Public classmovieinfo{[Databasegenerated (databasegeneratedoption.computed)] PublicDatetime? CreateDate {Get;Set; }}} Of course, when your model is successful you will see that the database is not set the default value, because the EF ORM is not supported to set the default value, to set up, can only be added manually, EF should not add this feature in the future, because in order to reduce the. NET native objects and database data conversion between the variables, When the model's data comes from the database automatically generating data, there is a good chance that the. NET object state cannot be traced. Therefore, it is not possible to specify default values in the database when using entity Framewrok.
Default value settings in ASP.