Files
SecMPS/api_sqlsugar/VolPro.Core/Generic/GenericOracleProvider.cs
2026-05-15 23:22:48 +08:00

50 lines
1.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
}
}
}