Closed gmf520 closed 6 years ago
utf8mb4
,下面是一个可用的配置文件
[mysqld]
user=mysql
character-set-server=utf8mb4
default_authentication_plugin=mysql_native_password
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
"MySql": {
"DbContextTypeName": "OSharp.Entity.DefaultDbContext,OSharp.EntityFrameworkCore",
"ConnectionString": "Server=127.0.0.1;UserId=root;Password=abcd123456;Database=osharpns.demo-dev;charset='utf8';Allow User Variables=True",
"DatabaseType": "MySql",
"LazyLoadingProxiesEnabled": true,
"AuditEntityEnabled": true,
"AutoMigrationEnabled": true
}
SqlServerDefaultDbContextMigrationPack.cs
, SqlServerDesignTimeDefaultDbContextFactory
两个文件,添加MySqlDefaultDbContextMigrationPack.cs
, MySqlDesignTimeDefaultDbContextFactory
文件Oracle 11g 按照上文步骤,排除SqlServer 的 SqlServerDefaultDbContextMigrationPack.cs, SqlServerDesignTimeDefaultDbContextFactory 两个文件,添加OracleDefaultDbContextMigrationPack.cs, OracleDesignTimeDefaultDbContextFactory文件 Add-Migration Init update-database 报错:Object reference not set to an instance of an object.
@xiongjx 没用过Oracle,不是很清楚
OracleDesignTimeDefaultDbContextFactory.cs文件最下面有一个默认写的builder.UseSqlServer,改为builder.UseOracle,并且将页面中的SqlServer:替换为Oracle:,则不会再出现以上问题
OracleDesignTimeDefaultDbContextFactory.cs文件最下面有一个默认写的builder.UseSqlServer,改为builder.UseOracle,并且将页面中的SqlServer:替换为Oracle:,则不会再出现以上问题
OracleDesignTimeDefaultDbContextFactory.cs文件最下面原文就是builder.UseOracle,您说的“将页面中的SqlServer:替换为Oracle:”这句没看明白,能够提供个demo?
更新(2019/05/15)
- 版本:1.0.0
步骤
- 安装MySql5.7,编码要求
utf8mb4
,下面是一个可用的配置文件[mysqld] user=mysql character-set-server=utf8mb4 default_authentication_plugin=mysql_native_password [client] default-character-set=utf8mb4 [mysql] default-character-set=utf8mb4
- 更改配置类appsettings.json和appsettings.Development.json,确保没有指向上下文DefaultDbContext的SqlServer的配置节点,注意是两个文件的SqlServer的配置节点都要删掉,否则会报“数据上下文配置中存在多个配置节点指向同一个上下文类型”的错误,因为系统初始化时两个文件都会读取的然后创建的MySql的配置节点,示例如下:
"MySql": { "DbContextTypeName": "OSharp.Entity.DefaultDbContext,OSharp.EntityFrameworkCore", "ConnectionString": "Server=127.0.0.1;UserId=root;Password=abcd123456;Database=osharpns.demo-dev;charset='utf8';Allow User Variables=True", "DatabaseType": "MySql", "LazyLoadingProxiesEnabled": true, "AuditEntityEnabled": true, "AutoMigrationEnabled": true }
- 在Web项目下Startups文件夹下,排除SqlServer的
SqlServerDefaultDbContextMigrationPack.cs
,SqlServerDesignTimeDefaultDbContextFactory
两个文件,添加MySqlDefaultDbContextMigrationPack.cs
,MySqlDesignTimeDefaultDbContextFactory
文件- 删除网络工程下的迁移文件夹,重新进行数据迁移
- 可以跑起来了
最后运行之前需要先在NuGet控制台选中Web项目运行“Add-Migration init”来创建迁移记录,之后再运行就可以了
我使用MySql5.7试了一下,框架现在的代码(0.3.0-beta10)完全可以跑起来的,没有问题。步骤如下:
character-set-server=utf8
配置,重启MySql服务。SqlServerDefaultDbContextMigrationPack
和SqlServerDesignTimeDefaultDbContextFactory
两个类文件复制一份,更名为MySqlDefaultDbContextMigrationPack
和MysqlDesignTimeDefaultDbContextFactory
,将文件内容中的SqlServer
都替换成MySql
,因为这两套代码都是服务于同一个上下文类型DefaultDbContext
的,迁移的时候会重复,所以要将SqlServerDefaultDbContextMigrationPack
和SqlServerDesignTimeDefaultDbContextFactory
两个SqlServer的文件从项目中排除掉。appsettings.json
和appsettings.Development.json
,确保没有指向上下文DefaultDbContext
的SqlServer配置节点,注意是两个文件的SqlServer配置节点都要删掉,否则会报“数据上下文配置中存在多个配置节点指向同一个上下文类型”的错误,因为系统初始化时两个文件都会读取的。然后创建MySql的配置节点,示例如下:Add-Migration XXXX
命令创建迁移记录了,然后应该就能跑起来。