Delete
Table Of Contents
Delete Method
To delete entities from the data store you will need to call the Delete method on the entity's repository.
The Sharp Factory App generates one Repository per entity.
You will need an instance of the RepositoryContainer class to access your repositories.
The naming convention is RepositoryContainer.{Model Name}.{Sql Schema Name}.{Entity Name}.Delete
The Delete method has three overloads:
-
The first one takes an entity to be deleted.
This overload returns a boolean. True if succeeded, false if the entity does not exist.
-
The second overload takes a list of entities and returns void.
-
The third overload takes an instance of the Query class.
This overload returns a int that represents the number of deleted records.
This is one of the most powerful features available.
Delete Single
The following sample of C# code shows how to delete a Customer entity from the database:
Delete List
To delete a list you can just pass the List
The following sample of C# code shows how to delete a list of customer in the database:
Delete Where
This is perhaps one of the most powerful features of The Sharp Factory Framework.
It gives you the ability to delete all entities within a given query. This is a feature lacking in some of the most popular ORMs in the market.
Three steps are required:
-
First you need an instance of the Query class.
-
Second add your predicate and craft your query.
-
Third call the Delete method in the correct repository and pass the query instance.
The following sample of C# code shows how to delete "all Customers where Balance > 0 or (CreatedDate = today and (status = "new" or status = "inactive"))":