views:

33

answers:

1

For my Edit Profile page, all the items are from the User entity. Things like email, password, fullname, city, etc. I'm using ASP .NET MVC2 along with Entity Framework 4. I'm wondering if I should create a separate ProfileModel for my EditProfile View or if I should just use the User entity created by EF. My dilemmna is that if I created a ProfileModel, then I would be repeating myself (as all the properties are already in the User model), but on the other hand if I use the User model, then I'm not sure how I can add attributes (like [DisplayName("Password")]) since the User model is auto-generated.

I realize that the AccountModels that ship with MVC do define separate models that repeat fields like Password and Username that are already in User.

+2  A: 

You can (and should) add validation attributes for your existing entity classes using a 'buddy class'. See this post by ScottGu and search on the page for "buddy class" to find specifics:

http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx

Andrew Barber
Excellent, I saw this in the NerdDinner project, but forgot about it. Thanks for the link.
Prabhu
:) I was thinking along the exact lines you were in your question here when I first started reading about the validation attributes; they seem really nice, but if I can't attach them to the model objects, won't that be extra work? Then I came across that info, and I was very happy!
Andrew Barber
+1 - the combo of clientside and serverside under a single definiton on the model makes this very compelling..
jim