Several unique constrains on a single document in RavenDb

Let's say I have a class:

public class Person
{
   public string Name{get;set;}
   public string Email {get;set;}
   public string GoogleId {get;set;}
   public string FacebookId {get;set;}
}

If I want to make the email unique I will use the unique constraint bundle.

But I want to make both the googleId and the facebookId properties as a single unique constraint side by side with the email constraint (while non of them is the id). Is it possible?

Answers


Use the UniqueConstraints bundle:

public class Person
{
   public string Name {get;set;}
   [UniqueConstraint]
   public string Email {get;set;}
   public string GoogleId {get;set;}
   public string FacebookId {get;set;}
   [UniqueConstraint]
   public string GoogleAndFacebookIds { get;set; }
}

Just make sure you update GoogleAndFacebookIds everytime you update either GoogleId or FacebookId. I was doing this so much I ended up using a simple interface on all my classes that did this sort of thing:

public interface ICombinedConstraints
{
    string UniqueId { get; set; }
    void UpdateConstraints();
}

So,

public class Person : ICombinedConstraints
{
    public string Name{get;set;}
    [UniqueConstraint]
    public string Email {get;set;}
    public string GoogleId {get;set;}
    public string FacebookId {get;set;}
    [UniqueConstraint]
    public string UniqueId { get; set; }

    public void UpdateConstraints()
    {
        UniqueId = GoogleId + FacebookId;
    }
}

You cannot do that. Raven doesn't provide any possibility to enforce unique constraints on the property. If you want to do that you need separate sets of documents (see link below)

Unique constraints in Raven

Update:

It seems that you can also try to use bundles to implement unique constraints in the object.

Bundle: Unique constraints


Need Your Help

how to save two file from two different html file upload in same function using angularjs and MVC3

html angularjs html5 asp.net-mvc-3

here is my all code i am trying to upload small image and large image separate but angularjs not let me allow to do this, it only taking one file but not taking other one. plz anyone help with this.

iOS auto layout: how to design different layouts for iPad landscape and iPad portrait in Xcode storyboard?

ios objective-c size-classes ios-autolayout

I am new to size class and auto layout in iOS. I am practicing the same through a small application. Below is what I am trying to achieve through auto-layout and size-class. Below are the specific