Signum Framework Logo
"Open framework that encourages convention over configuration, using C# code,
not XML files, to model at the right level of abstraction and achieve deadlines.
...but also has a full Linq provider, and syncs the schema for you!"
Login
RSS

Search





Main
Index
Map
Videos
Download
Tutorials
Forum
FAQ



Image



PoweredBy

Edit

Introduction

Removing an entity from database is not frequent. Usually a custom user field with a boolean flag marking the entity as obsolete, or a nullable DateTime field for the FinishDate, serves our purposes better:

  • IdentifiableEntities should have their own... you know... identity, and they have the right to exist by themselves.
  • In good designed databases data is so related that removing a piece of it is not easy.

Also, if you have an entity that has some sub-entities not referenced anywhere else, and their life cycle is fixed by the parent entity, you should consider making them embedded entities. You can even have MList of EmbeddedEntity objects and they will be deleted and re-created each time you save the parent entity, so you don't need to delete them explicitly.

Anyway, if suddenly all this theory fails, and you need to delete some entities for performance reasons. We are currently not using ON DELETE CASCADE because we prefer code, not the database, to take control of deletes. Instead we provide you some Delete overloads that are able to make the removal of the rows at the entity abstraction. When you call Delete on an entity it will remove the entity and all the rows in relational tables (MList) that belong to them.

Edit

Delete Overloads

public static void Delete(Type type, int id) //Weak-Typed. Deletes an entity by Type an Id
public static void Delete<T>(this T ident) where T : IdentifiableEntity //Strong-Typed. Extension Method!. Deletes the entity

public static void Delete(Type type, IEnumerable<int> ids) //Weak-Typed. Deletes some entities given the type and the id of each of them. public static void Delete<T>(this IEnumerable<T> collection) where T : IdentifiableEntity //Strong-Typed. Deletes a collection of IdentifiableEntity


Creative Commons License Signum Framework Site by Signum Software is licensed under a Creative Commons Attribution 3.0 License.
Powered by ScrewTurn Wiki version 2.0.35.