/// <summary> /// The SimpleUpdate. /// </summary> /// <param name="table">The table<see cref="IFigures"/>.</param> /// <param name="buildMapping">The buildMapping<see cref="bool"/>.</param> /// <param name="updateKeys">The updateKeys<see cref="bool"/>.</param> /// <param name="updateExcept">The updateExcept<see cref="string[]"/>.</param> /// <param name="batchSize">The batchSize<see cref="int"/>.</param> /// <returns>The <see cref="int"/>.</returns> public int SimpleUpdate(IFigures table, bool buildMapping = false, bool updateKeys = false, string[] updateExcept = null, int batchSize = 500) { try { IFigures tab = table; IList <FieldMapping> nMaps = new List <FieldMapping>(); SqlAdapter afad = new SqlAdapter(_cn); StringBuilder sb = new StringBuilder(); int intSqlset = 0; sb.AppendLine(@" /* ---- SQL BANK START CMD ------ */ "); int count = 0; foreach (IFigure ir in table) { if (ir.GetType().DeclaringType != tab.FigureType) { if (buildMapping) { SqlMapper imapper = new SqlMapper(tab); } nMaps = tab.Rubrics.Mappings; } foreach (FieldMapping nMap in nMaps) { IDeck <int> co = nMap.ColumnOrdinal; IDeck <int> ko = nMap.KeyOrdinal; MemberRubric[] ic = tab.Rubrics.AsValues().Where(c => nMap.ColumnOrdinal.Contains(c.FieldId)).ToArray(); MemberRubric[] ik = tab.Rubrics.AsValues().Where(c => nMap.KeyOrdinal.Contains(c.FieldId)).ToArray(); if (updateExcept != null) { ic = ic.Where(c => !updateExcept.Contains(c.RubricName)).ToArray(); ik = ik.Where(c => !updateExcept.Contains(c.RubricName)).ToArray(); } string qry = BatchUpdateQuery(ir, nMap.DbTableName, ic, ik, updateKeys).ToString(); sb.Append(qry); count++; } if (count >= batchSize) { sb.AppendLine(@" /* ---- DATA BATCH EDataD CMD ------ */ "); intSqlset += afad.ExecuteUpdate(sb.ToString()); sb.Clear(); sb.AppendLine(@" /* ---- SQL BANK START CMD ------ */ "); count = 0; } } sb.AppendLine(@" /* ---- DATA BANK END CMD ------ */ "); intSqlset += afad.ExecuteUpdate(sb.ToString()); return(intSqlset); } catch (SqlException ex) { _cn.Close(); throw new SqlUpdateException(ex.ToString()); } }
/// <summary> /// The BatchUpdate. /// </summary> /// <param name="table">The table<see cref="IFigures"/>.</param> /// <param name="keysFromDeck">The keysFromDeck<see cref="bool"/>.</param> /// <param name="buildMapping">The buildMapping<see cref="bool"/>.</param> /// <param name="updateKeys">The updateKeys<see cref="bool"/>.</param> /// <param name="updateExcept">The updateExcept<see cref="string[]"/>.</param> /// <param name="batchSize">The batchSize<see cref="int"/>.</param> /// <returns>The <see cref="IDeck{IDeck{IFigure}}"/>.</returns> public IDeck <IDeck <IFigure> > BatchUpdate(IFigures table, bool keysFromDeck = false, bool buildMapping = false, bool updateKeys = false, string[] updateExcept = null, int batchSize = 250) { try { IFigures tab = table; IList <FieldMapping> nMaps = new List <FieldMapping>(); SqlAdapter afad = new SqlAdapter(_cn); StringBuilder sb = new StringBuilder(); IDeck <IDeck <IFigure> > nSet = new Album <IDeck <IFigure> >(); sb.AppendLine(@" /* ---- SQL BANK START CMD ------ */ "); int count = 0; foreach (IFigure ir in table) { if (ir.GetType().DeclaringType != tab.FigureType) { if (buildMapping) { SqlMapper imapper = new SqlMapper(tab, keysFromDeck); } nMaps = tab.Rubrics.Mappings; } foreach (FieldMapping nMap in nMaps) { IDeck <int> co = nMap.ColumnOrdinal; IDeck <int> ko = nMap.KeyOrdinal; MemberRubric[] ic = tab.Rubrics.AsValues().Where(c => nMap.ColumnOrdinal.Contains(c.FieldId)).ToArray(); MemberRubric[] ik = tab.Rubrics.AsValues().Where(c => nMap.KeyOrdinal.Contains(c.FieldId)).ToArray(); if (updateExcept != null) { ic = ic.Where(c => !updateExcept.Contains(c.RubricName)).ToArray(); ik = ik.Where(c => !updateExcept.Contains(c.RubricName)).ToArray(); } string qry = BatchUpdateQuery(ir, nMap.DbTableName, ic, ik, updateKeys).ToString(); sb.Append(qry); count++; } if (count >= batchSize) { sb.AppendLine(@" /* ---- DATA BATCH END CMD ------ */ "); IDeck <IDeck <IFigure> > bIFigures = afad.ExecuteUpdate(sb.ToString(), tab); if (nSet.Count == 0) { nSet = bIFigures; } else { foreach (IDeck <IFigure> its in bIFigures.AsValues()) { if (nSet.Contains(its)) { nSet[its].Put(its.AsValues()); } else { nSet.Add(its); } } } sb.Clear(); sb.AppendLine(@" /* ---- SQL BANK START CMD ------ */ "); count = 0; } } sb.AppendLine(@" /* ---- DATA BANK END CMD ------ */ "); IDeck <IDeck <IFigure> > rIFigures = afad.ExecuteUpdate(sb.ToString(), tab, true); if (nSet.Count == 0) { nSet = rIFigures; } else { foreach (IDeck <IFigure> its in rIFigures.AsValues()) { if (nSet.Contains(its)) { nSet[its].Put(its.AsValues()); } else { nSet.Add(its); } } } return(nSet); } catch (SqlException ex) { _cn.Close(); throw new SqlUpdateException(ex.ToString()); } }
/// <summary> /// The BulkUpdate. /// </summary> /// <param name="table">The table<see cref="IFigures"/>.</param> /// <param name="keysFromDeck">The keysFromDeck<see cref="bool"/>.</param> /// <param name="buildMapping">The buildMapping<see cref="bool"/>.</param> /// <param name="updateKeys">The updateKeys<see cref="bool"/>.</param> /// <param name="updateExcept">The updateExcept<see cref="string[]"/>.</param> /// <param name="tempType">The tempType<see cref="BulkPrepareType"/>.</param> /// <returns>The <see cref="IDeck{IDeck{IFigure}}"/>.</returns> public IDeck <IDeck <IFigure> > BulkUpdate(IFigures table, bool keysFromDeck = false, bool buildMapping = false, bool updateKeys = false, string[] updateExcept = null, BulkPrepareType tempType = BulkPrepareType.Trunc) { try { IFigures tab = table; if (tab.Count > 0) { IList <FieldMapping> nMaps = new List <FieldMapping>(); if (buildMapping) { SqlMapper imapper = new SqlMapper(tab, keysFromDeck); } nMaps = tab.Rubrics.Mappings; string dbName = _cn.Database; SqlAdapter afad = new SqlAdapter(_cn); afad.DataBulk(tab, tab.FigureType.Name, tempType, BulkDbType.TempDB); _cn.ChangeDatabase(dbName); IDeck <IDeck <IFigure> > nSet = new Album <IDeck <IFigure> >(); StringBuilder sb = new StringBuilder(); sb.AppendLine(@" /* ---- SQL BANK START CMD ------ */ "); foreach (FieldMapping nMap in nMaps) { sb.AppendLine(@" /* ---- TABLE BULK START CMD ------ */ "); MemberRubric[] ic = tab.Rubrics.AsValues().Where(c => nMap.ColumnOrdinal.Contains(c.FieldId)).ToArray(); MemberRubric[] ik = tab.Rubrics.AsValues().Where(c => nMap.KeyOrdinal.Contains(c.FieldId)).ToArray(); if (updateExcept != null) { ic = ic.Where(c => !updateExcept.Contains(c.RubricName)).ToArray(); ik = ik.Where(c => !updateExcept.Contains(c.RubricName)).ToArray(); } string qry = BulkUpdateQuery(dbName, tab.FigureType.Name, nMap.DbTableName, ic, ik, updateKeys).ToString(); sb.Append(qry); sb.AppendLine(@" /* ---- TABLE BULK END CMD ------ */ "); } sb.AppendLine(@" /* ---- SQL BANK END CMD ------ */ "); var bIFigures = afad.ExecuteUpdate(sb.ToString(), tab, true); if (nSet.Count == 0) { nSet = bIFigures; } else { foreach (IDeck <IFigure> its in bIFigures.AsValues()) { if (nSet.Contains(its)) { nSet[its].Put(its.AsValues()); } else { nSet.Add(its); } } } sb.Clear(); return(nSet); } else { return(null); } } catch (SqlException ex) { _cn.Close(); throw new SqlUpdateException(ex.ToString()); } }