EF6 connection MySQL Several issues summary

Source: Internet
Author: User

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

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.