title: MVC Model Confusion
body: <p>I have confusion regarding models when we have relations between multiple tables. Formerly, I was using views or stored procedures of SQL to manipulate data but now I am using Entity Framework so confused how my model should look like ?</p>
  
  <p>I have a table for <code>Users</code>, <code>UserImages</code>, <code>UserRoles</code>.</p>
  
  <p><code>UserImages</code> and <code>UserRoles</code> is referring to <code>UserID</code> from <code>Users</code> table.I am not sure how my model should be. While displaying data I generally use a view created in SQL server by joining these 2 tables. And when an user is edited or created I update these 3 tables.</p>
  
  <p>Not sure what should my model look like in this case ? Do I create a SQL server view and add it to edmx ? Or add 3 tables separately in EDMX and create custom properties in User model for those other 2 tables?</p>
  
  <p>[HttpPost]
          public ActionResult Create(UserFormViewModel UserView)
            {</p>
  
  <pre><code>        User user = UserView.User;
  
          try {
  
              if (ModelState.IsValid) {
                  repository.AddUser(user);
                  repository.Save();
  
                  return View(new UserFormViewModel(user));
              } else {
                  return View(new UserFormViewModel(user));
              }
          } catch (Exception ex) {
              ModelState.AddModelError("Error", ex.Message);
              return View(new UserFormViewModel(user));
          }
      }
  
  
  
  
  
  public class UserFormViewModel {
  
      UucsrRepository repository = new UucsrRepository();
  
      public User User { get; private set; }
      public SelectList States { get; private set; }
      public SelectList Genders { get; private set; }
      public SelectList RolesLists { get; private set; }
      public SelectList SelectedRolesLists{ get; private set; }
  
      public UserFormViewModel(User contact) {
          User = contact;
          States = new SelectList(repository.GetAllStates() ,"ShortName","Name");
          Genders = new SelectList(repository.GetAllGenders(), "Gender", "Description");
          RolesLists = new SelectList(repository.GetAllRolesLists(), "Id", "Name");
      }
  }
  </code></pre>
  
  <p>I am not sure how should I exactly handle the Adding role list and images here .</p>