Add unique constraints your entities when using RavenDB.
Example usage :
var uniqueProperties = new RavenUniqueEnforcer<User>();
uniqueProperties.AddProperty(x => x.Name);
uniqueProperties.AddProperty(x => x.Email);
using (var session = store.OpenSession())
{
try
{
//Should save
var user = new User() { Name = "John", Email = "john@gmail.com" };
new RavenUniqueInserter().StoreUnique(session,user, uniqueProperties);
//Should throw a UniqueConstraintViolationException exception
var user1 = new User() { Name = "John", Email = "john@gmail.com" };
new RavenUniqueInserter().StoreUnique(session, user1, uniqueProperties);
}
catch (UniqueConstraintViolationException)
{
// email address and name already in use
}
}