Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
ASP.NET MVC Model
Message
 
 
À
08/07/2013 11:01:42
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01577926
Message ID:
01577965
Vues:
55
>>>>>>I am learning how to create Model using EF (learning from various Pluralsight courses). So far what I understood is that the controller creates a model from EF and passes it to the View. And the examples I watched - so far - deal with only one table. But what if I need to use more that one table in the View? For example, a "main" table for the fields of the View and several tables used as look-ups? Does it mean that the controller then creates several models and passes to the View not one but several Models?
>>>>>>
>>>>>>TIA.
>>>>>
>>>>>You should add multiple tables in the EF model and define the relationships between them. If, as the classic example, you have Customer, Order and OrderDetail tables then the EF Customer entity will then have a collection of Orders and each Order will have a collection of OrderDetails.
>>>>
>>>>What if there is a table in DB/EF that has no relationship to the main table? E.g. Some Reference Code. But you want this table to be a pull-down of one of the fields of the, say, Order table. So that the user can - optionally - select/assign a certain code to the Order. How do you pass the collection of this ReferenceCode to the View?
>>>
>>>Tables in the EF designer don't *have* to have a relationship - Add the table in the designer as an independent entity. But in the example you give it seems to me that there is a relationship - the ReferenceCode in the Order table relates to an item in the table with the list of options ?
>>
>>The only thing is set in the database, as far as relationship, is Foreign Key Constraint for the field Reference in ReferenceCode table and the same field name (Reference) in the Orders table. And I don't know if this is the "relationship" that is needed for EF or there is something other than that.
>
>If the relationship exists in the database then it's usually best to preserve that relationship in the model but you will still need to use something like the DropDownListFor helper to populate the list for the browser.

Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform