Question 1. Chinese garbled problem
Connection string has been set Charset=utf8, but still garbled, workaround: Configure string field Conventions support Unicode
protected Override void onmodelcreating (Dbmodelbuilder modelBuilder) { modelbuilder.properties<string> (). Configure (x = X.isunicode (true));}
Question 2. Database cascading Delete Issues
The exception thrown is similar to "Introducing FOREIGN KEY constraint" on table "may cause cycles or multiple cascade paths.", Workaround: Delete the default pair of cascade deletions about Availability
protected Override void onmodelcreating (Dbmodelbuilder modelBuilder) { ModelBuilder.Conventions.Remove< Onetomanycascadedeleteconvention>();}
Question 3. Defining UNIQUE constraints
EF6 supports defining unique constraints by adding index attributes to attributes that need to be defined as unique constraints.
true )]publicstringgetset; }
Question 4. __migrationhistory the primary key exceeds the maximum length problem in the table
The custom database configuration class, which inherits from Dbconfiguration, belongs to the global configuration class with the following code:
Public classmysqlconfiguration:dbconfiguration{ Publicmysqlconfiguration () {Sethistorycontext ("MySql.Data.MySqlClient", (conn, schema) =NewMysqlhistorycontext (conn, schema)); }} Public classmysqlhistorycontext:historycontext{ PublicMysqlhistorycontext (DbConnection existingconnection,stringDefaultschema):Base(ExistingConnection, Defaultschema) {}protected Override voidonmodelcreating (Dbmodelbuilder modelBuilder) {Base. Onmodelcreating (ModelBuilder); Modelbuilder.entity<HistoryRow> (). Property (H = H.migrationid). Hasmaxlength ( -). IsRequired (); Modelbuilder.entity<HistoryRow> (). Property (H = h.contextkey). Hasmaxlength ( $). IsRequired (); }}
EF6 connection MySQL Several issues summary