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