Constraints a property as unique at the database level




Set to true if the property must be unique (this is a persistent call and will query the database)

Be aware that it's possible (though uncommon in practice) for a uniqueness constraint validation to pass but a subsequent save of the data to fail due to a uniqueness constraint enforced at the database level. The only way to prevent this would be to use the SERIALIZABLE transaction isolation level (bad for performance) or just be prepared to get an exception to this effect at some point.

Scope of unique constraint can be specified by specifying the name of another property of the same class, or list of such names. The semantics in these cases is: pair of constrained property value and scope property value must be unique (or combination of constrained property value and all scope property values must be unique).



In the above example group name must be unique in one department but there might be groups with same name in different departments.

Another example:


In this example login must be unique in group and department. There might be same logins in different groups or different departments.

This constraint influences schema generation.

Error Code: className.propertyName.unique