This commit is contained in:
sunkaixuan
2017-09-27 11:25:59 +08:00
parent c489d0c073
commit f65b20fd38
2 changed files with 20 additions and 3 deletions

View File

@@ -28,6 +28,7 @@ namespace SqlSugar
public bool IsNoInsertNull { get; set; }
public bool IsReturnIdentity { get; set; }
public EntityInfo EntityInfo { get; set; }
public Dictionary<string, int> OracleSeqInfoList { get; set; }
#endregion
#region SqlTemplate

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SqlSugar
namespace SqlSugar
{
public class OracleInsertable<T> : InsertableProvider<T> where T : class, new()
{
@@ -11,8 +11,24 @@ namespace SqlSugar
{
return this.EntityInfo.Columns.Where(it => it.OracleSequenceName.IsValuable()).Select(it => it.DbColumnName).ToList();
}
protected override void PreToSql() {
protected override void PreToSql()
{
var identities = GetIdentityKeys();
var insertCount = InsertObjs.Count();
InsertBuilder.OracleSeqInfoList = new Dictionary<string, int>();
if (identities.IsValuable()&& insertCount > 1)
{
Check.Exception(identities.Count != identities.Distinct().Count(), "The field sequence needs to be unique");
foreach (var seqName in identities)
{
int seqBeginValue = 0;
this.Ado.ExecuteCommand("alter sequence " + seqName + " increment by " + insertCount);
seqBeginValue = this.Ado.GetInt("select " + seqName + ".Nextval from dual") - insertCount;
this.Ado.ExecuteCommand("alter sequence " + seqName + " increment by " + 1);
InsertBuilder.OracleSeqInfoList.Add(seqName,seqBeginValue);
}
}
base.PreToSql();
}
}
}