Q:

Forcing Id and UserName to be unique in ASP.NET MVC 3 Model

In my ASP.NET web site users model, I want both Guid Id's and String UserNames to be unique. I am going to map my model objects to a DB using Entity Framework.
Is there a build-in attribute or some other mechanism that facilitates this common constraint in ASP.NET MVC? Or am I bound to manually checking user name uniqueness at user register form?  

A:

Firstly, in my opinion, MVC, or your front end application shouldn't be responsible for doing this. 
Unique Id and unique Username are the constraints that should be enforced on the database, otherwise, you are making an assumption that the only way to register users is from your website.
Entity framework has attributes for enforcing unique constraints. More info here: http://blogs.msdn.com/b/efdesign/archive/2011/03/09/unique-constraints-in-the-entity-framework.aspx 
Finally, regarding the Ids of your users, I would consider auto generating these within the database, rather then your front end application.

