using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace SqlSugar { public partial class InsertableProvider : IInsertable where T : class, new() { public SqlSugarProvider Context { get; set; } public IAdo Ado { get { return Context.Ado; } } public ISqlBuilder SqlBuilder { get; set; } public InsertBuilder InsertBuilder { get; set; } public bool IsMappingTable { get { return this.Context.MappingTables != null && this.Context.MappingTables.Any(); } } public bool IsMappingColumns { get { return this.Context.MappingColumns != null && this.Context.MappingColumns.Any(); } } public bool IsSingle { get { return this.InsertObjs.Length == 1; } } public EntityInfo EntityInfo { get; set; } public List MappingColumnList { get; set; } private List IgnoreColumnNameList { get; set; } internal bool IsOffIdentity { get; set; } public T[] InsertObjs { get; set; } public MappingTableList OldMappingTableList { get; set; } public bool IsAs { get; set; } public bool IsEnableDiffLogEvent { get; set; } public DiffLogModel diffModel { get; set; } internal Action RemoveCacheFunc { get; set; } #region Core public void AddQueue() { if (this.InsertObjs!=null&&this.InsertObjs.Length > 0&& this.InsertObjs[0]!=null) { var sqlObj = this.ToSql(); this.Context.Queues.Add(sqlObj.Key, sqlObj.Value); } } public virtual int ExecuteCommand() { if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null) { return 0; } string sql = _ExecuteCommand(); var result = Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); After(sql, null); if (result == -1) return this.InsertObjs.Count(); return result; } public virtual string ToSqlString() { var sqlObj = this.ToSql(); var result = sqlObj.Key; if (result == null) return null; result = UtilMethods.GetSqlString(this.Context.CurrentConnectionConfig, sqlObj); return result; } public virtual KeyValuePair> ToSql() { InsertBuilder.IsReturnIdentity = true; PreToSql(); AutoRemoveDataCache(); string sql = InsertBuilder.ToSqlString(); RestoreMapping(); return new KeyValuePair>(sql, InsertBuilder.Parameters); } public async Task> ExecuteReturnPkListAsync() { return await Task.Run(() => ExecuteReturnPkList()); } public virtual List ExecuteReturnPkList() { var pkInfo= this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey == true); Check.ExceptionEasy(pkInfo==null,"ExecuteReturnPkList need primary key", "ExecuteReturnPkList需要主键"); Check.ExceptionEasy(this.EntityInfo.Columns.Count(it => it.IsPrimarykey == true)>1, "ExecuteReturnPkList ,Only support technology single primary key", "ExecuteReturnPkList只支技单主键"); var isIdEntity = pkInfo.IsIdentity|| (pkInfo.OracleSequenceName.HasValue()&&this.Context.CurrentConnectionConfig.DbType==DbType.Oracle); if (isIdEntity&&this.InsertObjs.Length==1) { return InsertPkListIdentityCount1(pkInfo); } else if (isIdEntity && this.InsertBuilder.ConvertInsertReturnIdFunc == null) { return InsertPkListNoFunc(pkInfo); } else if (isIdEntity && this.InsertBuilder.ConvertInsertReturnIdFunc != null) { return InsertPkListWithFunc(pkInfo); } else if (pkInfo.UnderType == UtilConstants.LongType) { return InsertPkListLong(); } else { return InsertPkListGuid(pkInfo); } } public virtual int ExecuteReturnIdentity() { if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null) { return 0; } string sql = _ExecuteReturnIdentity(); var result = 0; if (InsertBuilder.IsOleDb) { var isAuto = false; if (this.Context.Ado.IsAnyTran() == false && this.Context.CurrentConnectionConfig.IsAutoCloseConnection) { isAuto = this.Context.CurrentConnectionConfig.IsAutoCloseConnection; this.Context.CurrentConnectionConfig.IsAutoCloseConnection = false; } result = Ado.GetInt(sql.Split(';').First(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); result = Ado.GetInt(sql.Split(';').Last(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); if (this.Context.Ado.IsAnyTran() == false && isAuto) { this.Ado.Close(); this.Context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto; } } else { result = Ado.GetInt(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); } After(sql, result); return result; } public virtual long ExecuteReturnBigIdentity() { if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null) { return 0; } string sql = _ExecuteReturnBigIdentity(); long result = 0; if (InsertBuilder.IsOleDb) { var isAuto = false; if (this.Context.Ado.IsAnyTran()==false&&this.Context.CurrentConnectionConfig.IsAutoCloseConnection) { isAuto = this.Context.CurrentConnectionConfig.IsAutoCloseConnection; this.Context.CurrentConnectionConfig.IsAutoCloseConnection = false; } result = Convert.ToInt64(Ado.GetScalar(sql.Split(';').First(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray())); result = Convert.ToInt64(Ado.GetScalar(sql.Split(';').Last(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray())); if (this.Context.Ado.IsAnyTran() == false && isAuto) { this.Ado.Close(); this.Context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto; } } else { result= Convert.ToInt64(Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray())); } After(sql, result); return result; } public virtual long ExecuteReturnSnowflakeId() { if (this.InsertObjs.Length > 1) { return this.ExecuteReturnSnowflakeIdList().First(); } var id = SnowFlakeSingle.instance.getID(); var entity = this.Context.EntityMaintenance.GetEntityInfo(); var snowProperty=entity.Columns.FirstOrDefault(it => it.IsPrimarykey && it.PropertyInfo.PropertyType == UtilConstants.LongType); Check.Exception(snowProperty==null, "The entity sets the primary key and is long"); Check.Exception(snowProperty.IsIdentity == true, "SnowflakeId IsIdentity can't true"); foreach (var item in this.InsertBuilder.DbColumnInfoList.Where(it=>it.PropertyName==snowProperty.PropertyName)) { item.Value = id; snowProperty?.PropertyInfo.SetValue(this.InsertObjs.First(), id); } this.ExecuteCommand(); return id; } public List ExecuteReturnSnowflakeIdList() { List result = new List(); var entity = this.Context.EntityMaintenance.GetEntityInfo(); var snowProperty = entity.Columns.FirstOrDefault(it => it.IsPrimarykey && it.PropertyInfo.PropertyType == UtilConstants.LongType); Check.Exception(snowProperty == null, "The entity sets the primary key and is long"); Check.Exception(snowProperty.IsIdentity == true, "SnowflakeId IsIdentity can't true"); foreach (var item in this.InsertBuilder.DbColumnInfoList.Where(it => it.PropertyName == snowProperty.PropertyName)) { var id = SnowFlakeSingle.instance.getID(); item.Value = id; result.Add(id); var obj = this.InsertObjs.ElementAtOrDefault(item.TableId); if (obj != null) { snowProperty?.PropertyInfo.SetValue(obj, id); } } this.ExecuteCommand(); return result; } public async Task ExecuteReturnSnowflakeIdAsync() { var id = SnowFlakeSingle.instance.getID(); var entity = this.Context.EntityMaintenance.GetEntityInfo(); var snowProperty = entity.Columns.FirstOrDefault(it => it.IsPrimarykey && it.PropertyInfo.PropertyType == UtilConstants.LongType); Check.Exception(snowProperty == null, "The entity sets the primary key and is long"); Check.Exception(snowProperty.IsIdentity == true, "SnowflakeId IsIdentity can't true"); foreach (var item in this.InsertBuilder.DbColumnInfoList.Where(it => it.PropertyName == snowProperty.PropertyName)) { item.Value = id; snowProperty?.PropertyInfo.SetValue(this.InsertObjs.First(), id); } await this.ExecuteCommandAsync(); return id; } public async Task> ExecuteReturnSnowflakeIdListAsync() { List result = new List(); var entity = this.Context.EntityMaintenance.GetEntityInfo(); var snowProperty = entity.Columns.FirstOrDefault(it => it.IsPrimarykey && it.PropertyInfo.PropertyType == UtilConstants.LongType); Check.Exception(snowProperty == null, "The entity sets the primary key and is long"); Check.Exception(snowProperty.IsIdentity == true, "SnowflakeId IsIdentity can't true"); foreach (var item in this.InsertBuilder.DbColumnInfoList.Where(it => it.PropertyName == snowProperty.PropertyName)) { var id = SnowFlakeSingle.instance.getID(); item.Value = id; result.Add(id); var obj = this.InsertObjs.ElementAtOrDefault(item.TableId); if (obj != null) { snowProperty?.PropertyInfo.SetValue(obj, id); } } await this.ExecuteCommandAsync(); return result; } public virtual T ExecuteReturnEntity() { ExecuteCommandIdentityIntoEntity(); return InsertObjs.First(); } public virtual bool ExecuteCommandIdentityIntoEntity() { var result = InsertObjs.First(); var identityKeys = GetIdentityKeys(); if (identityKeys.Count == 0) { var snowColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey && it.UnderType == UtilConstants.LongType); if (snowColumn!=null) { if (Convert.ToInt64(snowColumn.PropertyInfo.GetValue(result)) == 0) { var id = this.ExecuteReturnSnowflakeId(); snowColumn.PropertyInfo.SetValue(result, id); } else { ExecuteCommand(); } return true; } else { return this.ExecuteCommand() > 0; } } var idValue = ExecuteReturnBigIdentity(); Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys"); var identityKey = identityKeys.First(); object setValue = 0; if (idValue > int.MaxValue) setValue = idValue; else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(uint))) { setValue = Convert.ToUInt32(idValue); } else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(ulong))) { setValue = Convert.ToUInt64(idValue); } else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(ushort))) { setValue = Convert.ToUInt16(idValue); } else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(short))) { setValue = Convert.ToInt16(idValue); } else setValue = Convert.ToInt32(idValue); this.Context.EntityMaintenance.GetProperty(identityKey).SetValue(result, setValue, null); return idValue > 0; } public async Task ExecuteCommandAsync() { if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null) { return 0; } string sql = _ExecuteCommand(); var result =await Ado.ExecuteCommandAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); After(sql, null); if (result == -1) return this.InsertObjs.Count(); return result; } public virtual async Task ExecuteReturnIdentityAsync() { if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null) { return 0; } string sql = _ExecuteReturnIdentity(); var result = 0; if (InsertBuilder.IsOleDb) { var isAuto = false; if (this.Context.Ado.IsAnyTran() == false && this.Context.CurrentConnectionConfig.IsAutoCloseConnection) { isAuto = this.Context.CurrentConnectionConfig.IsAutoCloseConnection; this.Context.CurrentConnectionConfig.IsAutoCloseConnection = false; } result = Ado.GetInt(sql.Split(';').First(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); result = Ado.GetInt(sql.Split(';').Last(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); if (this.Context.Ado.IsAnyTran() == false && isAuto) { this.Ado.Close(); this.Context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto; } } else { result = await Ado.GetIntAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); } After(sql, result); return result; } public async Task ExecuteReturnEntityAsync() { await ExecuteCommandIdentityIntoEntityAsync(); return InsertObjs.First(); } public async Task ExecuteCommandIdentityIntoEntityAsync() { var result = InsertObjs.First(); var identityKeys = GetIdentityKeys(); if (identityKeys.Count == 0) { var snowColumn = this.EntityInfo.Columns.FirstOrDefault(it => it.IsPrimarykey&& it.UnderType == UtilConstants.LongType); if (snowColumn != null) { if (Convert.ToInt64(snowColumn.PropertyInfo.GetValue(result)) == 0) { var id = await this.ExecuteReturnSnowflakeIdAsync(); snowColumn.PropertyInfo.SetValue(result, id); } else { await this.ExecuteCommandAsync(); } return true; } else { return await this.ExecuteCommandAsync() > 0; } } var idValue =await ExecuteReturnBigIdentityAsync(); Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys"); var identityKey = identityKeys.First(); object setValue = 0; if (idValue > int.MaxValue) setValue = idValue; else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(uint))) { setValue = Convert.ToUInt32(idValue); } else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(ulong))) { setValue = Convert.ToUInt64(idValue); } else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(ushort))) { setValue = Convert.ToUInt16(idValue); } else if (this.EntityInfo.Columns.Any(it => it.IsIdentity && it.PropertyInfo.PropertyType == typeof(short))) { setValue = Convert.ToInt16(idValue); } else setValue = Convert.ToInt32(idValue); this.Context.EntityMaintenance.GetProperty(identityKey).SetValue(result, setValue, null); return idValue > 0; } public virtual async Task ExecuteReturnBigIdentityAsync() { if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null) { return 0; } string sql = _ExecuteReturnBigIdentity(); long result = 0; if (InsertBuilder.IsOleDb) { var isAuto = false; if (this.Context.Ado.IsAnyTran() == false && this.Context.CurrentConnectionConfig.IsAutoCloseConnection) { isAuto = this.Context.CurrentConnectionConfig.IsAutoCloseConnection; this.Context.CurrentConnectionConfig.IsAutoCloseConnection = false; } result = Ado.GetInt(sql.Split(';').First(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); result = Ado.GetInt(sql.Split(';').Last(), InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()); if (this.Context.Ado.IsAnyTran() == false && isAuto) { this.Ado.Close(); this.Context.CurrentConnectionConfig.IsAutoCloseConnection = isAuto; } } else { result = Convert.ToInt64(await Ado.GetScalarAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray())); } After(sql, result); return result; } #endregion #region Setting public IParameterInsertable UseParameter() { var result = new ParameterInsertable(); result.Context= this.Context; result.Inserable = this; return result; } public IInsertable AsType(Type tableNameType) { return AS(this.Context.EntityMaintenance.GetEntityInfo(tableNameType).DbTableName); } public IInsertable AS(string tableName) { this.InsertBuilder.AsName = tableName; return this; ; } public IInsertable IgnoreColumns(Expression> columns) { if (columns == null) return this; var ignoreColumns = InsertBuilder.GetExpressionValue(columns, ResolveExpressType.ArraySingle).GetResultArray().Select(it => this.SqlBuilder.GetNoTranslationColumnName(it)).ToList(); this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => !ignoreColumns.Any(ig => ig.Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase))).ToList(); this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => !ignoreColumns.Any(ig => ig.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))).ToList(); return this; } public IInsertable IgnoreColumns(params string[] columns) { if (columns == null) columns = new string[] { }; this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => !columns.Any(ig => ig.Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase))).ToList(); this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => !columns.Any(ig => ig.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))).ToList(); return this; } public IInsertable MySqlIgnore() { this.InsertBuilder.MySqlIgnore = true; return this; } public IInsertable InsertColumns(Expression> columns) { if (columns == null) return this; var ignoreColumns = InsertBuilder.GetExpressionValue(columns, ResolveExpressType.ArraySingle).GetResultArray().Select(it => this.SqlBuilder.GetNoTranslationColumnName(it)).ToList(); this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => ignoreColumns.Any(ig => ig.Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase)) || ignoreColumns.Any(ig => ig.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))).ToList(); return this; } public IInsertable InsertColumns(string[] columns) { if (columns == null) return this; this.InsertBuilder.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.Where(it => columns.Any(ig => ig.Equals(it.PropertyName, StringComparison.CurrentCultureIgnoreCase))|| columns.Any(ig => ig.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))).ToList(); return this; } public IInsertable With(string lockString) { if (this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer) this.InsertBuilder.TableWithString = lockString; return this; } public IInsertable IgnoreColumns(bool ignoreNullColumn, bool isOffIdentity = false) { Check.Exception(this.InsertObjs.Count() > 1&& ignoreNullColumn, ErrorMessage.GetThrowMessage("ignoreNullColumn NoSupport batch insert", "ignoreNullColumn 不支持批量操作")); this.IsOffIdentity = isOffIdentity; if (this.InsertBuilder.LambdaExpressions == null) this.InsertBuilder.LambdaExpressions = InstanceFactory.GetLambdaExpressions(this.Context.CurrentConnectionConfig); this.InsertBuilder.IsNoInsertNull = ignoreNullColumn; return this; } public IInsertable RemoveDataCache() { this.RemoveCacheFunc = () => { var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; CacheSchemeMain.RemoveCache(cacheService, this.Context.EntityMaintenance.GetTableName()); }; return this; } public IInsertable RemoveDataCache(string likeString) { this.RemoveCacheFunc = () => { var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; CacheSchemeMain.RemoveCacheByLike(cacheService, likeString); }; return this; } public MySqlBlukCopy UseMySql() { return new MySqlBlukCopy(this.Context, this.SqlBuilder, InsertObjs); } public SqlServerBlukCopy UseSqlServer() { PreToSql(); var currentType = this.Context.CurrentConnectionConfig.DbType; Check.Exception(currentType != DbType.SqlServer, "UseSqlServer no support " + currentType); SqlServerBlukCopy result = new SqlServerBlukCopy(); result.DbColumnInfoList =this.InsertBuilder.DbColumnInfoList.GroupBy(it => it.TableId).ToList(); result.InsertBuilder = this.InsertBuilder; result.Builder = this.SqlBuilder; result.Context = this.Context; result.Inserts=this.InsertObjs; return result; } public OracleBlukCopy UseOracle() { PreToSql(); var currentType = this.Context.CurrentConnectionConfig.DbType; Check.Exception(currentType != DbType.Oracle, "UseSqlServer no support " + currentType); OracleBlukCopy result = new OracleBlukCopy(); result.DbColumnInfoList = this.InsertBuilder.DbColumnInfoList.GroupBy(it => it.TableId).ToList(); result.InsertBuilder = this.InsertBuilder; result.Builder = this.SqlBuilder; result.Context = this.Context; result.Inserts = this.InsertObjs; InsertBuilder.IsBlukCopy = true; return result; } public IInsertable EnableDiffLogEventIF(bool isDiffLogEvent, object diffLogBizData) { if (isDiffLogEvent) { return EnableDiffLogEvent(diffLogBizData); } return this; } public IInsertable EnableDiffLogEvent(object businessData = null) { //Check.Exception(this.InsertObjs.HasValue() && this.InsertObjs.Count() > 1, "DiffLog does not support batch operations"); diffModel = new DiffLogModel(); this.IsEnableDiffLogEvent = true; diffModel.BusinessData = businessData; diffModel.DiffType = DiffType.insert; return this; } public ISubInsertable AddSubList(Expression> items) { Check.Exception(GetPrimaryKeys().Count == 0, typeof(T).Name + " need Primary key"); Check.Exception(GetPrimaryKeys().Count > 1, typeof(T).Name + "Multiple primary keys are not supported"); //Check.Exception(this.InsertObjs.Count() > 1, "SubInserable No Support Insertable(List)"); //Check.Exception(items.ToString().Contains(".First().")==false, items.ToString()+ " not supported "); if (this.InsertObjs == null || this.InsertObjs.Count() == 0) { return new SubInsertable(); } SubInsertable result = new SubInsertable(); result.InsertObjects = this.InsertObjs; result.Context = this.Context; result.SubList = new List(); result.SubList.Add(new SubInsertTreeExpression() { Expression= items }); result.InsertBuilder = this.InsertBuilder; result.Pk = GetPrimaryKeys().First(); result.Entity = this.EntityInfo; return result; } public ISubInsertable AddSubList(Expression> tree) { Check.Exception(GetPrimaryKeys().Count == 0, typeof(T).Name + " need Primary key"); Check.Exception(GetPrimaryKeys().Count > 1, typeof(T).Name + "Multiple primary keys are not supported"); //Check.Exception(this.InsertObjs.Count() > 1, "SubInserable No Support Insertable(List)"); //Check.Exception(items.ToString().Contains(".First().")==false, items.ToString()+ " not supported "); if (this.InsertObjs == null || this.InsertObjs.Count() == 0) { return new SubInsertable(); } SubInsertable result = new SubInsertable(); result.InsertObjects = this.InsertObjs; result.Context = this.Context; result.SubList = new List(); result.InsertBuilder = this.InsertBuilder; result.Pk = GetPrimaryKeys().First(); result.Entity = this.EntityInfo; result.AddSubList(tree); return result; } public SplitInsertable SplitTable(SplitType splitType) { SplitTableContext helper = new SplitTableContext(Context) { EntityInfo = this.EntityInfo }; helper.CheckPrimaryKey(); SplitInsertable result = new SplitInsertable(); result.Context = this.Context; result.EntityInfo = this.EntityInfo; result.Helper = helper; result.SplitType = splitType; result.TableNames = new List>(); foreach (var item in this.InsertObjs) { var splitFieldValue = helper.GetValue(splitType, item); var tableName=helper.GetTableName(splitType, splitFieldValue); result.TableNames.Add(new KeyValuePair(tableName,item)); } result.Inserable = this; return result; } public SplitInsertable SplitTable() { var splitTableAttribute = typeof(T).GetCustomAttribute(); if (splitTableAttribute != null) { return SplitTable((splitTableAttribute as SplitTableAttribute).SplitType); } else { Check.Exception(true,$" {typeof(T).Name} need SplitTableAttribute"); return null; } } #endregion } }