Open SpiritLing opened 4 years ago
使用社区包Pomelo.EntityFrameworkCore.MySql
dotnet ef dbcontext scaffold "Server=localhost;Database=blogsite;User=root;Password=***;TreatTinyAsBoolean=true;" "Pomelo.EntityFrameworkCore.MySql" --project BlogSite.Database -f -o Mysql2 -c BlogSiteDbContext
NET5.0的要怎么写运行命令?
Method not found: 'Void Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping..ctor(System.String, System.Type, System.Nullable1<System.Data.DbType>, Boolean, System.Nullable
1
System.TypeLoadException: Method 'Create' in type 'Pomelo.EntityFrameworkCore.MySql.Query.ExpressionVisitors.Internal.MySqlSqlTranslatingExpressionVisitorFactory' from assembly 'Pomelo.EntityFrameworkCore.MySql, Version=3.1.1.0, Culture=neutral, PublicKeyToken=2cc498582444921b' does not have an implementation.
System.TypeLoadException: Method 'Create' in type 'Pomelo.EntityFrameworkCore.MySql.Query.ExpressionVisitors.Internal.MySqlSqlTranslatingExpressionVisitorFactory' from assembly 'Pomelo.EntityFrameworkCore.MySql, Version=3.1.1.0, Culture=neutral, PublicKeyToken=2cc498582444921b' does not have an implementation.
你使用的是那个命令,然后本地都安装了那些包和运行的.net版本
包版本如下: Microsoft.EntityFrameworkCore -version 5.0.2 Microsoft.EntityFrameworkCore.Design -version 5.0.2 Microsoft.EntityFrameworkCore.Tools -version 5.0.2 MySql.Data.EntityFrameworkCore -version 8.0.22 Pomelo.EntityFrameworkCore.MySql 3.2.4
.netsdk版本 2.1-5.0
Scaffold-DbContext "server=localhost;port=3306;user=root;password=123456;database=test" MySql.Data.EntityFrameworkCore -OutputDir Models -F
报Method not found: 'Void Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping..ctor(System.String, System.Type, System.Nullable1<System.Data.DbType>, Boolean, System.Nullable
1
我调用时 检测到的包版本在依赖项约束之外: Pomelo.EntityFrameworkCore.MySql 3.2.4 需要 Microsoft.EntityFrameworkCore.Relational (>= 3.1.8 && < 5.0.0),但版本 Microsoft.EntityFrameworkCore.Relational 5.0.2 已解决。
是必须要降级吗? 现在不支持?
包版本如下: Microsoft.EntityFrameworkCore -version 5.0.2 Microsoft.EntityFrameworkCore.Design -version 5.0.2 Microsoft.EntityFrameworkCore.Tools -version 5.0.2 MySql.Data.EntityFrameworkCore -version 8.0.22 Pomelo.EntityFrameworkCore.MySql 3.2.4
.netsdk版本 2.1-5.0 Scaffold-DbContext "server=localhost;port=3306;user=root;password=123456;database=test" MySql.Data.EntityFrameworkCore -OutputDir Models -F 报Method not found: 'Void Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping..ctor(System.String, System.Type, System.Nullable
1<System.Data.DbType>, Boolean, System.Nullable
1)'.我调用时 检测到的包版本在依赖项约束之外: Pomelo.EntityFrameworkCore.MySql 3.2.4 需要 Microsoft.EntityFrameworkCore.Relational (>= 3.1.8 && < 5.0.0),但版本 Microsoft.EntityFrameworkCore.Relational 5.0.2 已解决。
等明天我给你看下
@alng0812 我这边测试也是出现问题了,估计.net 5的问题和mysql官方开发的包有啥问题,你可以使用 Pomelo 社区包,安装了这个就不要安装其他的了,Pomelo包出现问题可以直接给提Issus
可以了 nutget里没有5.0的mysql包 用.NET CLI安装:
dotnet add package Pomelo.EntityFrameworkCore.MySql --version 5.0.0-alpha.2 就可以了
配置文件改一下
var connectionString = Configuration.GetConnectionString("XXContextConnection");
ServerVersion serverVersion = ServerVersion.AutoDetect(connectionString);
services.AddDbContext
https://blog.spiritling.cn/posts/daefc0a4/
.Net Core + EF + mysql 从数据库生成实体