Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8183443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:09:48+00:00 2026-06-07T01:09:48+00:00

If I have a main table, lets say orders, and a sub table of

  • 0

If I have a main table, lets say orders, and a sub table of items and the items table has a fields for item number BUT it also has a nullable (optional) field for color that applied only to certain items. How would I update the items table, at the same time as the orders table, using Entity Framework?

Here is a code example of what I have so far. Two problems, I’m only entering one of my items and, from what my research indicates, I can’t add another field to the items table?

    foreach (Guid c in AllItems)
    { Items.OrderItemID = Guid.NewGuid();
      ITemsOrderID = order.OrderID;
      ITems.ItemID = c;
      If (ItemID = ItemThatLetsYouChoseAColorID)
      {
          Items.ItemColorID = ColorID;
      } else {
          Items.ItemColorID = null;
      }
     }
     context.Orders.AddObject(Orders);
     context.Items.AddObject(Items);
     context.SaveChanges();

My Orders table gets a record inserted, and the Items gets ONE record inserted. I’m missing something basic here, I’m afraid. BTW, this is Entity Framework 4.0, which. I believe, does not require the use of EntityKey.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:09:50+00:00Added an answer on June 7, 2026 at 1:09 am

    You’re adding an object to the Items collection only one time after the scope of your foreach.

    Have you tested something like:

    foreach (Guid c in AllItems)
    {
        var Item = new Item();
    
        Item.OrderItemID = Guid.NewGuid();
        Item.OrderID = order.OrderID;
        Item.ItemID = c;
        If (ItemID = ItemThatLetsYouChoseAColorID)
        {
            Item.ItemColorID = ColorID;
        }
        else
        {
            Item.ItemColorID = null;
        }
    
        context.Items.AddObject(Items);
    }
    
    context.Orders.AddObject(order);
    context.SaveChanges();
    

    And I’m not sure to understand what you mean by

    I can’t add another field to the items table

    You should be more precise about what you actually expect. Insert a row, add a column in the table…? What is a “field”?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have main table called 'Employee' and another slave table called 'EmployeeTypes' that has
If I have a table TABLE_1 with, lets say 5 columns: COL1 | COL2
Let's say I have 3 MySQL table. A song db called songs that has
Let's say I have a Students table on my main page, with Country, Name,
I have a main Table, with several child tables. TableA and TableAChild1 and TableAChild2.
I have a structure where the main table is USER, other tables include CATEGORY
I have a SQL Server database with 500,000 records in table main . There
I have four different tables, one main SPECIAL table containing only id's that reference
I have a table naming related_products, Where products_id is the main product. and related_products_ids
I have 3 tables I need to join. The contracts table is the main

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.