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:
- 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
New contributor
|
show 3 more comments
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:
- 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
New contributor
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
|
show 3 more comments
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:
- 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
New contributor
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:
- 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
c# entity-framework frameworks entity
New contributor
New contributor
edited 2 days ago
Henk Holterman
206k22225394
206k22225394
New contributor
asked 2 days ago
Metal-Frog
11
11
New contributor
New contributor
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
|
show 3 more comments
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
|
show 3 more comments
active
oldest
votes
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.
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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