Implementing a soft-delete pattern
Sometimes you do not want to delete the information from the database, but instead to mark it as deleted. This technique is called soft-delete. In this recipe, we will show you how to implement a soft-delete pattern with NHibernate.
How to do it…
- Create a new class library project named
SoftDeleteExample
. - Install the
NHibernate
package using the NuGet Package Manager Console by executing the following command:Install-Package NHibernate
- Add the
ISoftDeletable
interface using the following code:public interface ISoftDeletable { bool IsDeleted { get; } DateTime? DeletedAt { get; } }
- Add an
App.config
with a standard NHibernate configuration. - Just before the end of the
sessionfactory
element, add the following three ...
Get NHibernate 4.x Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.