Frequently asked questions in MVC

Source: Internet
Author: User

1. The model backing the ' musicstoredbcontext ' context has changed since the database was created.

Consider using Code first migrations to update the database

Movie This table is used to record the model version number, each time you regenerate the database it will re-assign a new value to the Modelhash column.
is different from the original database.

2. Automatically change the table name of the database to a complex number, resulting in an error

Method One: Use Tableattribute to specify the mapped table name for the entity class

1[Table ("User")]2  Public classUser3 {4 [Key]5      Public intId {Get;Set; }6      Public stringUSN {Get;Set; }7      Public stringPWD {Get;Set; }8      PublicDateTime Created {Get;Set; }9}
View Code

Method Two: Overriding the Onmodelcreating method does not allow you to change the table name to a plural form

 Public classusercontext:dbcontext{ PublicUserContext ():Base("Name=sqlserver")    { }    protected Override voidonmodelcreating (Dbmodelbuilder modelBuilder) {modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>(); }     PublicDbset<user> User {Get;Set; }}
View Code

Frequently asked questions in MVC

Related Article

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.