jeudi 2 juillet 2015

In repository pattern, should I use database model as my View model or should I create separate ViewModel for that?

Self explanatory, I have a model that map 1:1 with my DB for example:

public class User
{
    [Key]
    public int UserID { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

Is there any downside if I use this in my View cshtml for example :

@model User

Or should I create another ViewModel like this

public class UserViewModel
{
    [Required]
    public string FirstName { get; set; }
    [Required]
    public string LastName { get; set; }
}

and bind it to my View

@model UserViewModel

Aucun commentaire:

Enregistrer un commentaire