public static void SqlServerTransaction <T>(this T t, OperationType opType, bool containsIdentityColumn = false, T newRec = default(T)) where T : class, new() { SqlServerDbMapper <T> mapper = new SqlServerDbMapper <T>(); switch (opType) { case OperationType.Select: mapper.GetObjectInstance(t); break; case OperationType.Insert: mapper.Insert(t, containsIdentityColumn); break; case OperationType.Update: mapper.Update(t, newRec); break; case OperationType.Delete: mapper.Delete(t); break; default: mapper.Insert(t, containsIdentityColumn); break; } }
private void winGridViewPager1_OnDeleteSelected(object sender, EventArgs e) { if (MessageBox.Show("您确定删除选定的记录么?") == DialogResult.No) { return; } int[] rowSelected = this.gridView1.GetSelectedRows(); foreach (int iRow in rowSelected) { string id = this.gridView1.GetRowCellDisplayText(iRow, "Id"); SqlServerDbMapper <DishMenu> dishMenuMap = new SqlServerDbMapper <DishMenu>(); dishMenuMap.Delete(new DishMenu { Id = Convert.ToInt32(id) }); } this.gridControl1.DataSource = this.GetDataTable(); }
/// <summary> /// 删除对象实例到数据表. /// </summary> /// <param name="instance"></param> public void DeleteInstanceObj(T instance) { mapper.Delete(instance); }