The above code is based on the following resources:
-
This article explains how to create a new DataAttribute [Unique] whe can be used on properties of Entity Framework models. Upon Database initilization the models [Unique] properties are turned into unique indexes on the database. http://code.msdn.microsoft.com/windowsdesktop/CSASPNETUniqueConstraintInE-d357224a
-
This article (with modified code attached) creates validators in the business logic based on the models [Unique] attribute which then provide a nice wrror message to the user. http://blogs.microsoft.co.il/blogs/shimmy/archive/2012/01/23/validationattribute-that-validates-a-unique-field-against-its-fellow-rows-in-the-database.aspx