Skip to content

sphiecoh/Sphiecoh.UniqueContraints.RavenDb

Repository files navigation

Sphiecoh.UniqueContraints.RavenDb

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 
                    }
										
				}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages