Netcore mvc efcore simple framework construction + addition, deletion, modification and query

Netcore mvc efcore simple framework construction + addition, deletion, modification and query

Netcore mvc efcore simple framework construction + addition, deletion, modification and query The database used in this example is mysql; .net core framework, version (sdk) is 3.1. One: Create a net core version of mvc Target framework selection net core3.1 2: After the project is created, first install the nuget package you will use today (the downloaded package should preferably be version 3.1) Microsoft.EntityFrameworkCore; Microsoft.EntityFrameworkCore.Design; Microsoft.EntityFrameworkCore.Tools; Pomelo.EntityFrameworkCore.MySql; For example: (You can manually install using the nuget interface, or you can write statement installation) Three: Overall configuration 1. The database connection is in appsettings.json //Connect to database “AppConfig”: { “AesKey”: “11*222sdf52sf2f2fsdf/.*222,ssddd”, “DbConn span>”: “Server=localhost;port=3306;database=user;uid=root;pwd=root;Convert Zero Datetime=True; ” } 2. Create a class: AppConfig public classAppConfig { /// /// Aes key /// public string AesKey { get; set; } /// /// Database connection string /// public string DbConn { get; set; } } 3. Add a class: NetcoremvcDbcontext as the context and inherit: DbContext class public class NetcoremvcDbcontext : DbContext { private string span> _connectionString; public NetcoremvcDbcontext(IOptionsSnapshot options) { _connectionString = options.Value.DbConn; } protected override voidOnConfiguring(DbContextOptionsBuilder optionsBuilder) { var connectionString = _connectionString ; //Connect to the database UseMySql keyword //MaxBatchSize one An integer value indicating the maximum number of pages that will…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索