50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
using SqlSugar;
|
||
using System.Collections.Generic;
|
||
using System.Threading.Tasks;
|
||
using VolPro.Core.EFDbContext;
|
||
using VolPro.Core.Extensions.AutofacManager;
|
||
using VolPro.Core.UserManager;
|
||
using VolPro.Entity.DomainModels;
|
||
|
||
namespace VolPro.Core.Generic
|
||
{
|
||
/// <summary>
|
||
/// Oracle 通用 CRUD 实现
|
||
/// </summary>
|
||
public class GenericOracleProvider : GenericDbProviderBase
|
||
{
|
||
protected override string LeftQuote => "\"";
|
||
protected override string RightQuote => "\"";
|
||
|
||
public GenericOracleProvider() : base()
|
||
{
|
||
}
|
||
|
||
/// <summary>
|
||
/// Oracle 12c+ 使用 RETURNING col INTO :outParam 获取自增/序列主键
|
||
/// 批量插入时 Oracle 需 BULK COLLECT,暂不支持返回多行 id,返回 null
|
||
/// </summary>
|
||
protected override string BuildIdentitySql(TableColumnField keyColumn, bool batch = false)
|
||
{
|
||
if (batch)
|
||
{
|
||
return null;
|
||
}
|
||
return $"RETURNING {LeftQuote}{keyColumn.ColumnName}{RightQuote} INTO :newId";
|
||
}
|
||
|
||
/// <summary>
|
||
/// Oracle 使用输出参数获取 RETURNING 值,需 Execute 后读取参数
|
||
/// </summary>
|
||
protected override async Task<object> ExecuteInsertWithIdentityAsync(string insertSql, string identitySql, List<SugarParameter> parameters, TableColumnField keyColumn)
|
||
{
|
||
// SqlSugar 输出参数:new SugarParameter(name, null, true)
|
||
var outParam = new SugarParameter(":newId", null, true);
|
||
parameters.Add(outParam);
|
||
await ExcuteNonQueryAsync($"{insertSql} {identitySql}", parameters);
|
||
return outParam.Value;
|
||
}
|
||
}
|
||
}
|
||
|