I'm trying to find out mvc - I apologize in advance for all the stupid questions. What I did was created by mvc proejct based on an exsiting database, and then I cheated on it to try to understand what was created for me and how to create my own things. Unfortunately, since I am a new stackoverflow user, I cannot post an image of my project structure.
I have a parent controller and a child controller created using the wizard based on two separate tables that I have in my model. I want to display both of them in one view - ultimately in a webgrid and be able to modify the data for any parent or child. You can ignore the CombinedController. I was engaged in reading, and I found out that I had to create a presentation model that combines both parent and child at the model level, and then from there.
so I created this class:
Imports System.Data.Objects.DataClasses Public Class ParentAndChild Public Property myChildren As IEnumerable(Of Child) Public Property myParent as Parent End Class
I have a few questions:
Question 1
Should I add this ParentAndChild object to the .edmx file in order to create a controller and view it? I assume that I am really asking if I should first create a view in the sql database, show that the object appeared in .edmx, and then create the controller? Or can I just combine the two objects in the class? This is what I have done so far. I do not have sql View in my database joining these two tables. The reason why I ask is because when I create my controller, if I want to get all CRUD for free, I need to create using the Entity Framework. But I do not know what to specify for the data context.
Question 2
If I want the webgrid to somehow show all my parents and all their children, will the new ParentAndChild class work? I think this will only show details for one parent and his children. It seems to me that I need to create a list of parents .. and then add a set of modules in the parent list for each parent. But I do not know how to do this.
Question 3
How does entityframework know which modules are returned when I use my new class? I donโt define relationships anywhere ... Is it because in the .edmx file the system knows the relationships between the tables?
source share