NET Core driver is out, support EF core
Awaited starts out MySQL official. NET core driver is out and supports EF core.
Yesterday, MySQL officially released the. NET Core driver, which is still in preview, but the feature is already available.
NuGet Address:
Https://www.nuget.org/packages/MySql.Data.Core/
This is a brief introduction:. NET core uses dapper to operate the MySQL database, the. NET core MySQL official driver.
New Project
Create a new. NET Core Console Application Netcoremysql
Add Reference
Using the NuGet console to add
Install-package Mysql.data.core-preinstall-package Dapper
MySQL additions and deletions to check changes
Create a new test library and table in MySQL
To test the MySQL script used:
Create DATABASE ' test ' create TABLE ' user ' ( ' Id ' int (one) ' Not NULL auto_increment, ' UserName ' varchar (255) DEFAULT NULL, ' Url ' varchar (255) default NULL, ' age ' int (one) default null, PRIMARY KEY (' Id ')) Engine=innodb default CHARSET=GBK;
Create a new user class
public class User {public int Id {get; set;} public string UserName {get; set;} public string Url {get; set;} public int Age {get; set;} }
Below to operate MySQL additions and deletions to change
public static void Main (string[] args) {Encoding.registerprovider (codepagesencodingprovider.ins tance); Mysqlconnection con = new Mysqlconnection ("server=127.0.0.1;database=test;uid=root;pwd=;charset= ' GBK"; Sslmode=none "); New Data con. Execute ("INSERT into user values (null, ' Test ', ' http://www.cnblogs.com/linezero/', 18)"); Added data returns the self-increment id var id = con. Queryfirst<int> ("INSERT into user values (null, ' Linezero ', ' http://www.cnblogs.com/linezero/'); Select Last_ INSERT_ID (); "); Modify Data con. Execute ("Update user set UserName = ' linezero123 ' where Id = @Id", new {id = id}); Query data var list = con. Query<user> ("SELECT * from User"); foreach (var item in list) {Console.WriteLine ($) User name: {item. UserName} Link: {Item. URL} "); }//delete data con. Execute ("Delete from user where id = @Id", new {id = ID }); Console.WriteLine ("Results after deleting data"); List = con. Query<user> ("SELECT * from User"); foreach (var item in list) {Console.WriteLine ($) User name: {item. UserName} Link: {Item. URL} "); } console.readkey (); }
The most important point here: the link string to add Sslmode=none will not report an error : SSL not supported in this WinRT release.
Then simply use the dapper to manipulate the database, and more functions to view official documents.
Execution effect:
Github:https://github.com/linezero/blog/tree/master/netcoremysql
MySQL EF Core NuGet Address:
Https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore/
Command installation: Install-package Mysql.data.entityframeworkcore-pre
You can take a look at it or follow my previous EF core tutorials.
NET Core driver is out, support EF core