EditIntroduction
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. EditDelete Overloads
public static void Delete(Type type, int id)
public static void Delete<T>(this T ident) where T : IdentifiableEntity
public static void Delete(Type type, IEnumerable<int> ids)
public static void Delete<T>(this IEnumerable<T> collection) where T : IdentifiableEntity