Default value settings in ASP.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.