. Netcore in Efcore for MySQL finishing

Source: Internet
Author: User

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

Related Article

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.