时间:2021-07-01 10:21:17 帮助过:22人阅读
Program.cs 文件为:
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; namespace ConsoleApp1 { public class Program { public static void Main(string[] args) { var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); var configuration = builder.Build(); string connectionString = configuration.GetConnectionString("SampleConnection"); // Create an employee instance and save the entity to the database var entry = new Data1() { Id = 3, Name1 = "XingBing" }; using (var context = Data1ContextFactory.Create(connectionString)) { context.Add(entry); context.SaveChanges(); } Console.WriteLine($"Data1 was saved in the database with id: {entry.Id}"); Console.ReadKey(); } } }
appsettings.json 文件为:
{ "ConnectionStrings": { "SampleConnection": "server=XXXXXX.mysqldb.chinacloudapi.cn;userid=XXXXXX%YYYYYY;pwd=XXXXXXXXX;port=3306;database=xyudb;sslmode=none;" } }
project.json 文件为:
{ "version": "1.0.0-*", "buildOptions": { "debugType": "portable", "emitEntryPoint": true, "copyToOutput": { "include": "appsettings.json" } }, "dependencies": { "Microsoft.Extensions.Configuration": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.EntityFrameworkCore": "1.0.0", "MySql.Data.Core": "7.0.4-IR-191", "MySql.Data.EntityFrameworkCore": "7.0.4-IR-191" }, "frameworks": { "netcoreapp1.0": { "dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0" } }, "imports": [ "dnxcore50", "portable-net452+win81" ] } } }
MySql.Data.EntityFrameworkCore 7.0.7-m61
MySQL EF Core provider and Connector/Net 7.0.4 入门教程
更多精彩干活 请点击查看
欢迎有兴趣的朋友多多交流
A究院研究生 Azurecommunity@qq.com
如何使用 MySQL EntityFramework 组件处理 MYSQL PaaS DB
标签:json string ati 上推 extern 结果 技术分享 deb user