Skip to content
This repository has been archived by the owner on Nov 14, 2022. It is now read-only.

.Net Core + EF + mysql 从数据库生成实体 | SpiritLing #38

Open
SpiritLing opened this issue Feb 26, 2020 · 10 comments
Open

.Net Core + EF + mysql 从数据库生成实体 | SpiritLing #38

SpiritLing opened this issue Feb 26, 2020 · 10 comments

Comments

@SpiritLing
Copy link
Owner

https://blog.spiritling.cn/posts/daefc0a4/

.Net Core + EF + mysql 从数据库生成实体

@SpiritLing
Copy link
Owner Author

SpiritLing commented Jan 21, 2021

使用社区包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

@alng0812
Copy link

NET5.0的要怎么写运行命令?

@alng0812
Copy link

Method not found: 'Void Microsoft.EntityFrameworkCore.Storage.RelationalTypeMapping..ctor(System.String, System.Type, System.Nullable1<System.Data.DbType>, Boolean, System.Nullable1)'.报这个错

@alng0812
Copy link

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.

@SpiritLing
Copy link
Owner Author

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版本

@alng0812
Copy link

包版本如下:
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.Nullable1)'.

我调用时
检测到的包版本在依赖项约束之外: Pomelo.EntityFrameworkCore.MySql 3.2.4 需要 Microsoft.EntityFrameworkCore.Relational (>= 3.1.8 && < 5.0.0),但版本 Microsoft.EntityFrameworkCore.Relational 5.0.2 已解决。

@alng0812
Copy link

是必须要降级吗? 现在不支持?

@SpiritLing
Copy link
Owner Author

包版本如下:
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.Nullable1)'.

我调用时
检测到的包版本在依赖项约束之外: Pomelo.EntityFrameworkCore.MySql 3.2.4 需要 Microsoft.EntityFrameworkCore.Relational (>= 3.1.8 && < 5.0.0),但版本 Microsoft.EntityFrameworkCore.Relational 5.0.2 已解决。

等明天我给你看下

@SpiritLing
Copy link
Owner Author

@alng0812 我这边测试也是出现问题了,估计.net 5的问题和mysql官方开发的包有啥问题,你可以使用 Pomelo 社区包,安装了这个就不要安装其他的了,Pomelo包出现问题可以直接给提Issus

@alng0812
Copy link

alng0812 commented Feb 4, 2021

可以了 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(options =>
options.UseMySql(connectionString, serverVersion));

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants