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 9104015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:45:50+00:00 2026-06-17T01:45:50+00:00

I have an entity Order with a sub entity OrderDetail. I want to update

  • 0

I have an entity Order with a sub entity OrderDetail. I want to update the Order and add a new OrderDetail. How should i do this?

I’ve tried setting the state of the Order to modified but i get this error:

A referential integrity constraint violation occurred: The property values that define the referential constraints are not consistent between principal and dependent objects in the relationship.

Update:
After i’ve added the new OrderDetail, i want to update the order type which is part of primary key. I’ve tried to set the state of OrderDetail to modified but i get a new error:

Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.

  • 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-17T01:45:53+00:00Added an answer on June 17, 2026 at 1:45 am

    Try to put the new OrderDetail into Added state first before you set the Order to Modified:

    var newOrderDetail = order.OrderDetails.First();
    context.Entry(newOrderDetail).State = EntityState.Added;
    context.Entry(order).State = EntityState.Modified;
    

    This might work – or not, depending on the details of your model and scenario…

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

Sidebar

Related Questions

I have User and Order entity. When user creates order I should check that
I have two Entity classes: Order and OrderItem . Order contains a navigation property
I have an abstract entity called Block which contains two attributes: column and order
I have Entity Framework entities Events which have an EntityCollection of RSVP. I want
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
Suppose I have an Entity Order with OrderDetails as child preperty. I enable lazyloading
I am using Linq to Entities. Have an entity Order which has a nullable
Overview: I'm designing a restaurant management application, and I have an entity called Order
I have an entity container with this property /** * @ORM\OneToMany(targetEntity=BizTV\ContentManagementBundle\Entity\Content, mappedBy=container) */ private
If I have Order entity with a list of OrderDetails I can easily eager

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.