Fluent Validation MVC 5 – Unique ID

Friends, I am trying to figure out how to make sure that my manually entered Primary Key ID is unique through fluent validation. I researched and could not find an example. I am pretty sure I need to use the Predicate Validator (aka Must). Does anyone know
how to do this?

Immagine there are 2 users that opens the same action at the ( apparently) same time. How do you generate the id?

In my opinion the id should be either identity on database either a GUID

Only the Admin of the website will have the ability to create the ID, so it will not be an issue.

Cindy_Nords

Only the Admin of the website will have the ability to create the ID, so it will not be an issue.

Then id = last id in database +1 . However, I suppose you have a unique constraint in database.

The thing is, I enter the ID manually.

I have three fields:

ID = 1000

Form Name: Web

Form Price: $1000

The admin will enter the ID manually in a field.

Is there a way to validate it is unique with fluent validation?

you should post your question to the fluent validation board.

  https://fluentvalidation.codeplex.com/discussions

Good point. Will do!

Leave a Reply