First, MySQL official provides the EF core support for MySQL, but it is still in the preview version
Install-package MySql.Data.EntityFrameworkCore-preinstall-package MySql.Data.EntityFrameworkCore.Design -pre
The current package relies on Microsoft.entityframeworkcore, no API documentation is found, and MySql.Data.EntityFrameworkCore.Design usage is not found.
NuGet Package Address: Https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore/7.0.7-m61
Https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore.Design/6.10.1-beta
Second, simple use example
1. Handwriting Database context
/// <summary>///Database Context/// </summary> Public classmd5context:dbcontext{protected Override voidonconfiguring (Dbcontextoptionsbuilder optionsbuilder) {optionsbuilder.usemysql ("server=127.0.0.1;port=3306;database=md5data;uid=sa;pwd=123;"); } Public VirtualDbset<md5data> Md5data {Get;Set; }}
2. Handwritten entity database mapping, Model
[Table ("Md5data")]//table specified name is not supported in the current preview version Public classmd5data{[Key] Public intDataid {Get;Set; } Public stringplaintext {Get;Set; } Public stringUpperCase32 {Get;Set; } Public stringUpperCase16 {Get;Set; } Public intDencryptcount {Get;Set; } Public intEncryptcount {Get;Set; } PublicDateTime Addtime {Get;Set; }}
3. Debug Run
New Md5context (); List<Md5Data> list = _context.md5data.tolist (); return list. Select (q = q.plaintext). ToList ();
Third, the description
1.
Here's what to note:
Public dbset<blog> Blog {get; set;}
If the table name blog in MySQL is lowercase, it should be defined as the same as the table name, or it will be an error
2.Table () The comment for the table name is not currently supported.
More:
ASP. NET Core Webapi Getting Started (iii) cross-domain processing
ASP. NET Core Webapi get started (b) Simple example
JSON serialization processing in ASP.
. Netcore in Efcore for MySQL finishing