visual studio 2019从mysql数据库表通过命令自动生成实体类模型

写程序的赵童鞋 2020-07-19

visual studio2019对sql server的支持是很好,对mysql的话就有很多的坑了,主要是版本的冲突问题,无数次失败后记录下一次成功的2大关键步骤:
一、通过Nuget 安装依赖包,命令如下:
Install-package mysql.data.entity -Version 6.8.8
Install-package mysql.data -Version 6.10.9
Install-package mysqlConnector -Version 0.68.0
install-package pomelo.entityFrameWorkCore.mysql
install-package Microsoft.EntityFrameworkCore
install-package Microsoft.EntityFrameworkCore.Tool
二、 Scaffold-DbContext "Server=MysqlServerIP;Database=MysqlDatabaseName;UserID=YourMysqlUserID;Password=YourMysqlUserPassword;port=3306;Charset=utf8;pooling=true;Allow User Variables=True;" Pomelo.EntityFrameworkCore.MySql -OutputDir YourOutputdirPath -tables YourTableName

最后,强调一点,这个windows下测试成功的,命令不区分大小写,linux下面是区分大小写的。最重要的是版本冲突的解决。附上所有测试依赖包(get-package):
Id Versions ProjectName


BouncyCastle {1.8.3.1} testframework2
EntityFramework {6.2.0} testframework2
EntityFramework.zh-Hans {6.2.0} testframework2
Google.Protobuf {3.6.1} testframework2
K4os.Compression.LZ4 {1.1.11} testframework2
K4os.Compression.LZ4.Streams {1.1.11} testframework2
K4os.Hash.xxHash {1.0.6} testframework2
Microsoft.AspNet.Mvc {5.2.7} testframework2
Microsoft.AspNet.Mvc.zh-Hans {5.2.7} testframework2
Microsoft.AspNet.Razor {3.2.7} testframework2
Microsoft.AspNet.Razor.zh-Hans {3.2.7} testframework2
Microsoft.AspNet.WebApi {5.2.7} testframework2
Microsoft.AspNet.WebApi.Client {5.2.7} testframework2
Microsoft.AspNet.WebApi.Client.z... {5.2.7} testframework2
Microsoft.AspNet.WebApi.Core {5.2.7} testframework2
Microsoft.AspNet.WebApi.Core.zh-... {5.2.7} testframework2
Microsoft.AspNet.WebApi.WebHost {5.2.7} testframework2
Microsoft.AspNet.WebApi.WebHost.... {5.2.7} testframework2
Microsoft.AspNet.WebPages {3.2.7} testframework2
Microsoft.AspNet.WebPages.zh-Hans {3.2.7} testframework2
Microsoft.Bcl.AsyncInterfaces {1.1.1} testframework2
Microsoft.Bcl.HashCode {1.1.0} testframework2
Microsoft.CodeDom.Providers.DotN... {2.0.1} testframework2
Microsoft.CSharp {4.7.0} testframework2
Microsoft.EntityFrameworkCore {3.1.6} testframework2
Microsoft.EntityFrameworkCore.Ab... {3.1.6} testframework2
Microsoft.EntityFrameworkCore.An... {3.1.6} testframework2
Microsoft.EntityFrameworkCore.De... {3.1.6} testframework2
Microsoft.EntityFrameworkCore.Re... {3.1.6} testframework2
Microsoft.EntityFrameworkCore.Tools {3.1.6} testframework2
Microsoft.Extensions.Caching.Abs... {3.1.6} testframework2
Microsoft.Extensions.Caching.Memory {3.1.6} testframework2
Microsoft.Extensions.Configuration {3.1.6} testframework2
Microsoft.Extensions.Configurati... {3.1.6} testframework2
Microsoft.Extensions.Configurati... {3.1.6} testframework2
Microsoft.Extensions.DependencyI... {3.1.6} testframework2
Microsoft.Extensions.DependencyI... {3.1.6} testframework2
Microsoft.Extensions.Logging {3.1.6} testframework2
Microsoft.Extensions.Logging.Abs... {3.1.6} testframework2
Microsoft.Extensions.Options {3.1.6} testframework2
Microsoft.Extensions.Primitives {3.1.6} testframework2
Microsoft.Web.Infrastructure {1.0.0.0} testframework2
MySql.Data {6.10.9} testframework2
MySql.Data.Entity {6.8.8} testframework2
MySql.Data.EntityFrameworkCore {6.10.9} testframework2
MySqlConnector {0.68.0} testframework2
Newtonsoft.Json {12.0.2} testframework2
Pomelo.EntityFrameworkCore.MySql {3.1.1} testframework2
Pomelo.JsonObject {2.2.1} testframework2
SSH.NET {2016.1.0} testframework2
System.Buffers {4.5.1} testframework2
System.Collections.Immutable {1.7.1} testframework2
System.ComponentModel.Annotations {4.7.0} testframework2
System.Data.Odbc {4.7.0} testframework2
System.Diagnostics.DiagnosticSource {4.7.1} testframework2
System.Memory {4.5.4} testframework2
System.Numerics.Vectors {4.5.0} testframework2
System.Runtime.CompilerServices.... {4.7.1} testframework2
System.Threading.Tasks.Extensions {4.5.4} testframework2

相关推荐