feat: 支持对不同数据库的guid设置方式
This commit is contained in:
@@ -9,6 +9,7 @@ using SqlSugar;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.Domain;
|
||||
using Volo.Abp.Domain.Repositories;
|
||||
using Volo.Abp.Guids;
|
||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
using Yi.Framework.SqlSugarCore.Repositories;
|
||||
using Yi.Framework.SqlSugarCore.Uow;
|
||||
@@ -24,6 +25,31 @@ namespace Yi.Framework.SqlSugarCore
|
||||
var configuration = service.GetConfiguration();
|
||||
var section = configuration.GetSection("DbConnOptions");
|
||||
Configure<DbConnOptions>(section);
|
||||
var dbConnOptions = new DbConnOptions();
|
||||
section.Bind(dbConnOptions);
|
||||
|
||||
//很多人遗漏了这一点,不同的数据库,对于主键的使用规约不一样,需要根据数据库进行判断
|
||||
SequentialGuidType guidType;
|
||||
switch (dbConnOptions.DbType)
|
||||
{
|
||||
case DbType.MySql:
|
||||
case DbType.PostgreSQL:
|
||||
guidType= SequentialGuidType.SequentialAsString;
|
||||
break;
|
||||
case DbType.SqlServer:
|
||||
guidType = SequentialGuidType.SequentialAtEnd;
|
||||
break;
|
||||
case DbType.Oracle:
|
||||
guidType = SequentialGuidType.SequentialAsBinary;
|
||||
break;
|
||||
default:
|
||||
guidType = SequentialGuidType.SequentialAtEnd;
|
||||
break;
|
||||
}
|
||||
Configure<AbpSequentialGuidGeneratorOptions>(options =>
|
||||
{
|
||||
options.DefaultSequentialGuidType = guidType;
|
||||
});
|
||||
|
||||
service.TryAddScoped<ISqlSugarDbContext, SqlSugarDbContextFactory>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user