public void Run() { var _distinctdata = _alldata.SelectMany(e => e.BaseObject.Select(w => w.Key)).Distinct(); var ValidKeys = _tableInfo.ColumnInfos.Where(q => q.IsKey).Select(e => e.ColumnName).Intersect(_distinctdata).ToList(); var AllValidfields = _tableInfo.ColumnInfos.Select(e => e.ColumnName).Intersect(_distinctdata); if (ValidKeys.Count != _tableInfo.ColumnInfos.Where(e => e.IsKey).Select(e => e.ColumnName).Distinct().Count()) { Console.WriteLine($"Key missed -Type {_tableName} "); EmailSender sender = new EmailSender(); sender.SendEmailAsync("*****@*****.**", "Error--key", $"Key missed -Type {_tableName} "); } querybulder = new InsertQueryBuilder(AllValidfields, _tableName); List <SqlParameter> _paramsSql = new List <SqlParameter>(); int _index = 0; foreach (var item in _alldata) { List <string> stringparamForQuery = new List <string>(); foreach (var field in AllValidfields) { string param = $"@p{_index++}"; stringparamForQuery.Add(param); var dbpar = new SqlParameter(param, shcema[_tableName][field]); if (item.BaseObject.ContainsKey(field)) { dbpar.Value = QueryBuilderHelper.FormatSQLForDb(_tableName, field, item.BaseObject[field]); } else { dbpar.Value = DBNull.Value; } _paramsSql.Add(dbpar); } querybulder.AddQueryParametrs(stringparamForQuery.ToList()); if (_paramsSql.Count > InsertCommandParametersCount) { Execute(_paramsSql); _paramsSql = new List <SqlParameter>(); _index = 0; querybulder.Reset(); } } if (_paramsSql.Count > 0) { Execute(_paramsSql); _paramsSql = new List <SqlParameter>(); _index = 0; } }