我有一个简单的ASP.Net核心/实体框架核心项目,它使用LocalDB。它在Windows上编译和运行良好。
我想在Windows和Linux上构建和运行相同的项目。但是Linux不支持LocalDB。因此,我需要将项目配置为使用mySql --但只适用于Linux。
问:我如何配置我的项目,使我可以在LocalDB上使用mySql,而在Linux上使用mySql?
这就是我迄今为止尝试过的:
appsettings.json连接字符串:
{ "ConnectionStrings":{ "DefaultConnection":ConnectionStrings "mySqlConnection":"Server=localhost;port=3306;database=ManageCarDb;uid=dotnetuser;password=dotnetuser“},. <=我定义了两个不同的连接字符串:一个用于LocalDB,一个用于MySqlStartup.cs:
公共Configuration.GetConnectionString("mySqlConnection");ConfigureServices(IServiceCollection服务){ string env = Configuration.GetConnectionString("DefaultConnection");string connectionString;if (!string.IsNullOrEmpty(env) & env.Equals("Linux")) { connectionString =Configuration.GetConnectionString(“mySqlConnection”);services.AddDbContext(options => options.UseMySQL( connectionString ));}ConfigureServices{connectionString=Configuration.GetConnectionString(“DefaultConnection”);services.AddDbContext(options => options.UseSqlServer(connectionString));}
<=启动将有条件地调用MySql连接字符串/MySQL数据提供程序或默认/LocalDB1. deleted all binaries
2. `dotnet restore`
3. `dotnet ef migrations add newMigration -c ApplicationDbContext -v`<=这一切都很好
dotnet ef database update
<= 错误:表'ManageCarDb.__EFMigrationsHistory‘不存在问:考虑到我希望两个EF环境都有一个项目,我是否采取了正确的步骤?
还是我应该采取不同的方法?
发布于 2018-11-28 04:07:04
您应该使用`Pomelo.EntityFrameworkCore.MySql而不是甲骨文的MySql库。
我使用Pomelo.EntityFrameworkCore.MySql,它在我的项目中运行得很好。
Oracle的MySql库不像我尝试的那样支持迁移。这个图书馆面临几个问题
备注:我正在为甲骨文的网站找到一个关于这个问题的链接
Error: The method or operation is not implemented. while scaffolding MYSQL Database
https://stackoverflow.com/questions/53510805
复制相似问题