/// <summary> /// Save into database /// </summary> /// <param name="entries"></param> public void SubmitChanges(List <ResourceEntry> entries, bool deleteRowNotInResource) { SqlMaker gen = new SqlMaker(tname.FormalName) { PrimaryKeys = new string[] { name_column } }; StringBuilder builder = new StringBuilder(); int count = 0; int max = 1000; foreach (var entry in entries) { gen.Clear(); gen.Add(name_column, entry.Name); gen.Add(value_column, entry.NewValue); if (order_column != null) { gen.Add(order_column, entry.Index); } switch (entry.Action) { case DataRowAction.Add: builder.AppendLine(gen.Insert()); break; case DataRowAction.Change: builder.AppendLine(gen.Update()); break; case DataRowAction.Delete: if (deleteRowNotInResource) { builder.AppendLine(gen.Delete()); } break; } count = (count + 1) % max; if (count == 0) { ExecuteNonQuery(); } } ExecuteNonQuery(); void ExecuteNonQuery() { string SQL = builder.ToString(); builder.Clear(); if (!string.IsNullOrEmpty(SQL)) { SqlCmd cmd = new SqlCmd(tname.Provider, SQL); cmd.ExecuteNonQuery(); } } }
private void OperateOnSubmit(RowOperation operation, TEntity entity) { SqlMaker gen = this.Generator; var dict = broker.ToDictionary(entity); gen.AddRange(dict); string sql = null; switch (operation) { case RowOperation.Insert: sql = gen.Insert(); break; case RowOperation.Update: sql = gen.Update(); break; case RowOperation.InsertOrUpdate: sql = gen.InsertOrUpdate(); break; case RowOperation.Delete: sql = gen.Delete(); break; } if (sql == null) { return; } Context.CodeBlock.AppendLine <TEntity>(sql); var evt = new RowEvent { TypeName = typeof(TEntity).Name, Operation = operation, Row = gen.ToDictionary(), }; Context.RowEvents.Add(evt); gen.Clear(); }