EF core Operation MySQL

Source: Internet
Author: User

EF core Operation MySQL is currently officially available in the latest version: 8.0.1

The packages that need to be installed are:

Mysql.data

MySql.Data.EntityFrameworkCore

MySql.Data.EntityFrameworkCore.Design

Other installation packages do not install, if you install other versions of the dependency package will be error;

Then we can connect to MySQL.

 Public class Blog    {        publicintgetset;}          Public  string Get Set ; }          Public  Get Set ; }    }
 Public classAppdbcontext:dbcontext { PublicAppdbcontext () {} PublicDbset<blog> Blogs {Get;Set; } protected Override voidonconfiguring (Dbcontextoptionsbuilder optionsbuilder) {
Sslmodel=none This is related to the SSL protocol. If you do not specify an error Optionsbuilder.usemysql ("server=localhost;user=root;database=test;port=3306;password=****; Sslmode=none"); } }

1  class Program2     {3         4         Static voidMain (string[] args)5         {6 7             using(vardb =NewAppdbcontext ())8             {9 db. Database.ensurecreated ();TenDb. Blogs.add (NewBlog {Title ="http://blogs.msdn.com/adonet", Createtime =DateTime.Now}); One                 varCount =db. SaveChanges (); AConsole.WriteLine ("{0} Records saved to database", count); -  - Console.WriteLine (); theConsole.WriteLine ("All Blogs in database:"); -                 foreach(varBloginchdb. Blogs) -                 { -Console.WriteLine ("-{0}", blog. Title); +                 } -             } +  A console.readline (); at         } -}
View Code

Run results

The operation was successful.

Querying Database Results

Efcore operation MySQL database successfully;

EF core Operation MySQL

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.