locked
Adding List<OrderDeatils> to database RRS feed

  • Question

  • User-2111854606 posted

    In Entity I can just add this property, but how can I add it to SQL Server Database ?

    I am have an .edmx file that has been generated from my database.

    Friday, May 15, 2015 11:48 AM

Answers

  • User-821857111 posted

    The Northwind sample database provides a schema for managing orders. It has an Orders table with an OrderId as a primary key, and an OrderDetails table. The ROderDetails table contains multiple lines per order, each one detailing a specific item that forms part of the order. The OrderDetails table has a foreign key pointing to the Orders table. I recommend downloading that database and exploring it.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 18, 2015 1:56 AM

All replies

  • User-821857111 posted
    foreach(var item in MyOrderDetailsList)
    {
        context.OrderDetails.Add(item);
    }
    context.SaveChanges();



    Friday, May 15, 2015 12:11 PM
  • User-2111854606 posted

    I didn't really understand how it's related to the SQL database..

    Friday, May 15, 2015 3:49 PM
  • User-821857111 posted

    Perhaps I misunderstood your question. You said that you have an edmx file, which suggests you are using Entity Framework. The context takes care of connecting to the database, issuing the INSERT statement and saving all of your entities. 

    If you want plain ADO.NET code for inserting your order details into a database without using Entity framework, you need to provide the definition of your OrderDetails entity and the schema of the table it is saved in.

    Saturday, May 16, 2015 3:08 AM
  • User-2111854606 posted

    I am trying to understand the logic of Shop and which classes and database tables I need.

    From what I have understand I need a table that will store the data of the entire order and it will include:

    OrderID

    UserID

    Date

    And then the orderDetails will store each item to the order by the OrderID and it will include:

    OrderID

    ItemID

    Amount

    Price

    So then I will connect the OrderID between the two table, is there a better way to do it ?

    Saturday, May 16, 2015 5:00 AM
  • User-821857111 posted

    Where did you get the edmx file from?

    Saturday, May 16, 2015 3:43 PM
  • User-2111854606 posted

    I generated it from the database I created on SQL Server.

    I add new ADO.NET Entity Data Model:

    And then I chose the source.

    Saturday, May 16, 2015 4:35 PM
  • User-821857111 posted

    So you already have a database and a context? I'm sorry, I'm quite confused about what your question actually is.

    Sunday, May 17, 2015 3:42 PM
  • User-2111854606 posted

    I'm trying to build a store website, so I need a table for the orders and in any order there i suppose to be orderLines.

    So I am asking how I can relate between them.

    Sunday, May 17, 2015 5:33 PM
  • User-821857111 posted

    The Northwind sample database provides a schema for managing orders. It has an Orders table with an OrderId as a primary key, and an OrderDetails table. The ROderDetails table contains multiple lines per order, each one detailing a specific item that forms part of the order. The OrderDetails table has a foreign key pointing to the Orders table. I recommend downloading that database and exploring it.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 18, 2015 1:56 AM