NET Core driver is out, support EF core

Source: Internet
Author: User

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

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.