I’m thinking to develop a web / mobile application with MVC4. For what I know about ASP.NET MVC, it works great when you have a 1 to 1 relationship between a table and a model class, while I had some problems when you need to work with normalized database.
—UPDATE—
Even if in the past I used Linq to SQL, I’m thinking to use Entity Data Model (not sure yet, but it seems better at the first glance).
—
A stupid example:
**table person**
ID
Name
Surname
HairColorID
**table hairColor**
HairColorID
Color
I wish to know if a situation like that can be easily solved in MVC4, without too much code writing in order to map manually all the table. I mean, I don’t know if there are some easy ways to have in my Controllers something like:
public ActionResult About(Person person)
where person automatically join my two tables.
I break my application into several different layers using different projects.
other model classes that I will need for my app.
So, in this instance, what I would do if this was a read-only view is create an AboutPersonDisplayViewModel that looks like the following:
And if it were an editable view, I would have a separate view model like this:
In the database, you should have a relationship between the person and hairColor tables. So, when you build your view model, you simple get the person for the ID you want to look up and populate the AboutPersonViewModel with that person’s information and use the navigation properties to navigate to Person.HairColor to get the hair color for the ID stored.
Then, when I save, the service layer would validate the data and properly map/save the hair color chosen.
I hope this helps