You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Starting discussion about Simplier Delete of entities from #8.
Now, if we want to delete an entity, we can use direct SQL statement (ExecuteNonQuery), or DbSet. The disadvantage of ExecuteNonQuery is, that it does not have ane knowledge about entity type, so the SQL must be hand written. Disadvantage of DbSet is that we need to create an instance of the entity, just to have its ID. I'd like to have something which can be used without creating an entity instance:
_database.Delete<EntityType>(123)
We could support delete with condition (instead of just primary key):
Where to implement this (IDbSet, IDatabase...). And it should at least support int and long primary keys (generic of <TEntity, TKey>?), but better any keys (what about composite ones?).
What kind of expressions to support when deleting with condition and throw some exception if we cannot translate it into SQL.
ToDo:
Delete by id
Check if id has the same type as primary key property
Integration test for Delete by id
Delete by condition
Prototype
Implementation
Unit and integration tests
xml comments
Extension for easy calling Delete and Add operation.
Info to readme file.
The text was updated successfully, but these errors were encountered:
I suggest:
To maintain consistency, we implement these methods in DbSet, like others (Delete, Edit, Add). The records are not deleted immediately, but only after you confirm the changes with CommitChanges().
For easier calling in common situations we can create extension methods over IDatabase, which allow easy adding and deleting of records. This extension method wraps work with DbSet and makes it easy to call _database.Add(new Entity());, _database.Delete<EntityType>();
We will have the following new overloads of the Delete method:
Starting discussion about Simplier
Delete
of entities from #8.Now, if we want to delete an entity, we can use direct SQL statement (
ExecuteNonQuery
), orDbSet
. The disadvantage ofExecuteNonQuery
is, that it does not have ane knowledge about entity type, so the SQL must be hand written. Disadvantage ofDbSet
is that we need to create an instance of the entity, just to have its ID. I'd like to have something which can be used without creating an entity instance:We could support delete with condition (instead of just primary key):
Things to think about:
IDbSet
,IDatabase
...). And it should at least supportint
andlong
primary keys (generic of<TEntity, TKey>
?), but better any keys (what about composite ones?).ToDo:
Delete
andAdd
operation.The text was updated successfully, but these errors were encountered: