Entity Framework 6: How to design data model for related table/view?











up vote
-1
down vote

favorite














I'm new to EF. The first steps where quick and easy but now I'm stuck. I need help to design the data model in the right way.

I'm trying to create some kind of an order management. According to "code first" I've designed my classes and let EF create the database.

I have a class "Order" and a class "Item" which represents catalog items. Furthermore there is a class "OrderItems" which holds in each row the ids of an order and the catalog item (plus additional info).

The GUI has two data grids, on the left hand side the list of orders and on the right hand side the corresponding ordered items. BUT the view on the right hand side should not just show the id (from the OrderItems class) but the info from the catalog items.

To manage the orders the class "Order" has a collection property "Itemlist" where I add or remove the ordered items. To be able to display the catalog info in the grid on the right hand side I additionally have a class "ViewOrderItems" which has all id properties and the data from the catalog items. This is an ugly design - I manually have to update the list of the ViewOrderItems with every change in the OrderItems and vice versa. From the database point of view it is easy. I've manually created a database view which holds all data I need to show in the grid. But I couldn't manage to get this work.

I hope I could make it clear! So how do I have to design my classes to use EF as it should be done?



Here's a picture of the classes and link to a VS solution to show what I'm trying to do:



enter image description here




  • Classes: https://i.stack.imgur.com/PPc1a.png


  • SLN: https://itbtf-my.sharepoint.com/:u:/g/personal/tf_itbtf_onmicrosoft_com/Ee9swM_3z4ZAlMt3_Z4AANcB5i4UtLrxHhuuQ2bhjMdXjA?e=j0mcwu)


Best regards, Tom










share|improve this question









New contributor




Metal-Frog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • We don't like external links here. Try to post a summary of your classes.
    – Henk Holterman
    2 days ago










  • I've tryed to embed a picture but it did not work :(
    – Metal-Frog
    2 days ago










  • You don't need a picture. You have 3 classes, post an outline (10 lines per class). Include all the linking and Key properties.
    – Henk Holterman
    2 days ago










  • Your picture seems to be using EDMX, not code first.
    – Henk Holterman
    2 days ago










  • what is OrderItemID & Ordernumber in items model
    – Michel Hanna
    2 days ago

















up vote
-1
down vote

favorite














I'm new to EF. The first steps where quick and easy but now I'm stuck. I need help to design the data model in the right way.

I'm trying to create some kind of an order management. According to "code first" I've designed my classes and let EF create the database.

I have a class "Order" and a class "Item" which represents catalog items. Furthermore there is a class "OrderItems" which holds in each row the ids of an order and the catalog item (plus additional info).

The GUI has two data grids, on the left hand side the list of orders and on the right hand side the corresponding ordered items. BUT the view on the right hand side should not just show the id (from the OrderItems class) but the info from the catalog items.

To manage the orders the class "Order" has a collection property "Itemlist" where I add or remove the ordered items. To be able to display the catalog info in the grid on the right hand side I additionally have a class "ViewOrderItems" which has all id properties and the data from the catalog items. This is an ugly design - I manually have to update the list of the ViewOrderItems with every change in the OrderItems and vice versa. From the database point of view it is easy. I've manually created a database view which holds all data I need to show in the grid. But I couldn't manage to get this work.

I hope I could make it clear! So how do I have to design my classes to use EF as it should be done?



Here's a picture of the classes and link to a VS solution to show what I'm trying to do:



enter image description here




  • Classes: https://i.stack.imgur.com/PPc1a.png


  • SLN: https://itbtf-my.sharepoint.com/:u:/g/personal/tf_itbtf_onmicrosoft_com/Ee9swM_3z4ZAlMt3_Z4AANcB5i4UtLrxHhuuQ2bhjMdXjA?e=j0mcwu)


Best regards, Tom










share|improve this question









New contributor




Metal-Frog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • We don't like external links here. Try to post a summary of your classes.
    – Henk Holterman
    2 days ago










  • I've tryed to embed a picture but it did not work :(
    – Metal-Frog
    2 days ago










  • You don't need a picture. You have 3 classes, post an outline (10 lines per class). Include all the linking and Key properties.
    – Henk Holterman
    2 days ago










  • Your picture seems to be using EDMX, not code first.
    – Henk Holterman
    2 days ago










  • what is OrderItemID & Ordernumber in items model
    – Michel Hanna
    2 days ago















up vote
-1
down vote

favorite









up vote
-1
down vote

favorite













I'm new to EF. The first steps where quick and easy but now I'm stuck. I need help to design the data model in the right way.

I'm trying to create some kind of an order management. According to "code first" I've designed my classes and let EF create the database.

I have a class "Order" and a class "Item" which represents catalog items. Furthermore there is a class "OrderItems" which holds in each row the ids of an order and the catalog item (plus additional info).

The GUI has two data grids, on the left hand side the list of orders and on the right hand side the corresponding ordered items. BUT the view on the right hand side should not just show the id (from the OrderItems class) but the info from the catalog items.

To manage the orders the class "Order" has a collection property "Itemlist" where I add or remove the ordered items. To be able to display the catalog info in the grid on the right hand side I additionally have a class "ViewOrderItems" which has all id properties and the data from the catalog items. This is an ugly design - I manually have to update the list of the ViewOrderItems with every change in the OrderItems and vice versa. From the database point of view it is easy. I've manually created a database view which holds all data I need to show in the grid. But I couldn't manage to get this work.

I hope I could make it clear! So how do I have to design my classes to use EF as it should be done?



Here's a picture of the classes and link to a VS solution to show what I'm trying to do:



enter image description here




  • Classes: https://i.stack.imgur.com/PPc1a.png


  • SLN: https://itbtf-my.sharepoint.com/:u:/g/personal/tf_itbtf_onmicrosoft_com/Ee9swM_3z4ZAlMt3_Z4AANcB5i4UtLrxHhuuQ2bhjMdXjA?e=j0mcwu)


Best regards, Tom










share|improve this question









New contributor




Metal-Frog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.













I'm new to EF. The first steps where quick and easy but now I'm stuck. I need help to design the data model in the right way.

I'm trying to create some kind of an order management. According to "code first" I've designed my classes and let EF create the database.

I have a class "Order" and a class "Item" which represents catalog items. Furthermore there is a class "OrderItems" which holds in each row the ids of an order and the catalog item (plus additional info).

The GUI has two data grids, on the left hand side the list of orders and on the right hand side the corresponding ordered items. BUT the view on the right hand side should not just show the id (from the OrderItems class) but the info from the catalog items.

To manage the orders the class "Order" has a collection property "Itemlist" where I add or remove the ordered items. To be able to display the catalog info in the grid on the right hand side I additionally have a class "ViewOrderItems" which has all id properties and the data from the catalog items. This is an ugly design - I manually have to update the list of the ViewOrderItems with every change in the OrderItems and vice versa. From the database point of view it is easy. I've manually created a database view which holds all data I need to show in the grid. But I couldn't manage to get this work.

I hope I could make it clear! So how do I have to design my classes to use EF as it should be done?



Here's a picture of the classes and link to a VS solution to show what I'm trying to do:



enter image description here




  • Classes: https://i.stack.imgur.com/PPc1a.png


  • SLN: https://itbtf-my.sharepoint.com/:u:/g/personal/tf_itbtf_onmicrosoft_com/Ee9swM_3z4ZAlMt3_Z4AANcB5i4UtLrxHhuuQ2bhjMdXjA?e=j0mcwu)


Best regards, Tom







c# entity-framework frameworks entity






share|improve this question









New contributor




Metal-Frog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Metal-Frog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Henk Holterman

206k22225394




206k22225394






New contributor




Metal-Frog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Metal-Frog

11




11




New contributor




Metal-Frog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Metal-Frog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Metal-Frog is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • We don't like external links here. Try to post a summary of your classes.
    – Henk Holterman
    2 days ago










  • I've tryed to embed a picture but it did not work :(
    – Metal-Frog
    2 days ago










  • You don't need a picture. You have 3 classes, post an outline (10 lines per class). Include all the linking and Key properties.
    – Henk Holterman
    2 days ago










  • Your picture seems to be using EDMX, not code first.
    – Henk Holterman
    2 days ago










  • what is OrderItemID & Ordernumber in items model
    – Michel Hanna
    2 days ago




















  • We don't like external links here. Try to post a summary of your classes.
    – Henk Holterman
    2 days ago










  • I've tryed to embed a picture but it did not work :(
    – Metal-Frog
    2 days ago










  • You don't need a picture. You have 3 classes, post an outline (10 lines per class). Include all the linking and Key properties.
    – Henk Holterman
    2 days ago










  • Your picture seems to be using EDMX, not code first.
    – Henk Holterman
    2 days ago










  • what is OrderItemID & Ordernumber in items model
    – Michel Hanna
    2 days ago


















We don't like external links here. Try to post a summary of your classes.
– Henk Holterman
2 days ago




We don't like external links here. Try to post a summary of your classes.
– Henk Holterman
2 days ago












I've tryed to embed a picture but it did not work :(
– Metal-Frog
2 days ago




I've tryed to embed a picture but it did not work :(
– Metal-Frog
2 days ago












You don't need a picture. You have 3 classes, post an outline (10 lines per class). Include all the linking and Key properties.
– Henk Holterman
2 days ago




You don't need a picture. You have 3 classes, post an outline (10 lines per class). Include all the linking and Key properties.
– Henk Holterman
2 days ago












Your picture seems to be using EDMX, not code first.
– Henk Holterman
2 days ago




Your picture seems to be using EDMX, not code first.
– Henk Holterman
2 days ago












what is OrderItemID & Ordernumber in items model
– Michel Hanna
2 days ago






what is OrderItemID & Ordernumber in items model
– Michel Hanna
2 days ago



















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Metal-Frog is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372956%2fentity-framework-6-how-to-design-data-model-for-related-table-view%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Metal-Frog is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Metal-Frog is a new contributor. Be nice, and check out our Code of Conduct.













Metal-Frog is a new contributor. Be nice, and check out our Code of Conduct.












Metal-Frog is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372956%2fentity-framework-6-how-to-design-data-model-for-related-table-view%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen