public int Delete(Query query) { var srcName = new QTable(query.Table.Name); var schema = GetSchema(); var dataClass = schema.FindClassByID(query.Table.Name); if (dataClass != null) { var ids = ObjectContainerStorage.GetObjectIds(query); return(ObjectContainerStorage.Delete(ids)); } // check for relation table var relation = schema.FindRelationshipByID(query.Table.Name); if (relation != null) { var rels = ObjectContainerStorage.LoadRelations(query.Table.Name, query.Condition).ToArray(); ObjectContainerStorage.RemoveRelation(rels); return(rels.Length); } return(UnderlyingDalc.Delete(query)); }
public void Update(DataTable t) { var schema = GetSchema(); var dataClass = schema.FindClassByID(t.TableName); if (dataClass != null) { foreach (DataRow r in t.Rows) { switch (r.RowState) { case DataRowState.Added: InsertDataRow(dataClass, r); break; case DataRowState.Modified: UpdateDataRow(dataClass, r); break; case DataRowState.Deleted: DeleteDataRow(dataClass, r); break; } } t.AcceptChanges(); return; } // check for relation table var relation = schema.FindRelationshipByID(t.TableName); if (relation != null) { foreach (DataColumn c in t.Columns) { if (c.ColumnName != "subject_id" && c.ColumnName != "object_id") { throw new ArgumentException(String.Format("{0} does not exist in {1}", c.ColumnName, t.TableName)); } } if (!t.Columns.Contains("subject_id")) { throw new ArgumentException("subject_id column is required"); } if (!t.Columns.Contains("object_id")) { throw new ArgumentException("object_id column is required"); } foreach (DataRow r in t.Rows) { switch (r.RowState) { case DataRowState.Added: ObjectContainerStorage.AddRelation( new ObjectRelation( Convert.ToInt64(r["subject_id"]), relation, Convert.ToInt64(r["object_id"]))); break; case DataRowState.Deleted: ObjectContainerStorage.RemoveRelation( new ObjectRelation( Convert.ToInt64(r["subject_id", DataRowVersion.Original]), relation, Convert.ToInt64(r["object_id", DataRowVersion.Original])) ); break; default: throw new NotSupportedException(String.Format("Relation doesn't support row state {0}", r.RowState)); } } t.AcceptChanges(); return; } UnderlyingDalc.Update(t); }