Create a custom Content Type with a unique restraint on a field

Topics: Customizing Orchard
May 27, 2014 at 3:39 PM
Hey guys


I can't figure out how to do this, I've created a content type on my Migrations.cs file, simple enough, just a couple of Fields converted into to parts added to the content type definition. Now what I need is to find a way to restrict the value of a given field to be unique, meaning when the user tries to create or edit content of this type the value of this field must be unique to all other content of this type. For example, if I have the following code:
    public class Migrations : DataMigrationImpl {

        public int Create() {
            ContentDefinitionManager.AlterPartDefinition(
                "RegistrationNumberPart",
                b => b
                .WithField("RegistrationNumberPartInputField", f => f
                    .OfType("InputField").WithDisplayName("Vehicle Registration")
                    .WithSetting("InputFieldSettings.Hint", "Vehicle Registration Number")
                    .WithSetting("InputFieldSettings.Required", "True")
                )
            );
            ContentDefinitionManager.AlterTypeDefinition(
                "Vehicle",
                resource => resource
                .WithPart("RegistrationNumberPart")

                .Creatable()
            );
I can make the Registration Number required easily enough, but I can't figure out how do I make it unique... Can you guys shed some light onto this matter?

I noticed some examples that people create custom record for their content use a custom content part that extends that record, and add that part to their content type... I find that this would be a bit of an overkill just to get a unique value validation... is that the only way?