/// <summary> /// Saves the many to many. /// </summary> private void SaveManyToMany() { foreach(TableSchema.ManyToManyRelationship m2m in ManyToManyCollection) { TableSchema.Table mapTable = DataService.GetSchema(m2m.MapTableName, ProviderName); CheckBoxList chk = (CheckBoxList)FindControl(mapTable.ClassName); if(chk != null) { ListItemCollection listItems = new ListItemCollection(); foreach(ListItem item in chk.Items) { if(item.Selected) listItems.Add(item); } //using(TransactionScope ts = new TransactionScope()) //{ // using(SharedDbConnectionScope connScope = new SharedDbConnectionScope()) // { SqlQuery qryDelete = new Delete().From(mapTable).Where(m2m.MapTableLocalTableKeyColumn).IsEqualTo(PrimaryKeyControlValue); qryDelete.Execute(); foreach(ListItem selectedItem in listItems) { Insert qryInsert = new Insert(mapTable, false); qryInsert.Value(mapTable.GetColumn(m2m.MapTableLocalTableKeyColumn), PrimaryKeyControlValue); qryInsert.Value(mapTable.GetColumn(m2m.MapTableForeignTableKeyColumn), selectedItem.Value); qryInsert.Execute(); } // } // ts.Complete(); //} } } }
/// <summary> /// Deletes the record. /// </summary> protected void DeleteRecord() { if(!CanDelete) throw new SecurityException(String.Format("This row can not be deleted as it has {0} read-only fields", listReadOnlyColumns.Count)); SqlQuery qryDelete = new Delete().From(TableSchema).Where(TableSchema.PrimaryKey).IsEqualTo(PrimaryKeyControlValue); qryDelete.Execute(); }