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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:31:34+00:00 2026-06-17T04:31:34+00:00

I have a process that creates an object that is responsible for inserting into

  • 0

I have a process that creates an object that is responsible for inserting into header /detail records. If I run the code to insert into the table on its own, every thing runs fine. However, when I call that code as a separate class within a loop I
get an exception:

System.Data.Entity.Infrastructure.DbUpdateException was unhandled
Message=The INSERT statement conflicted with the FOREIGN KEY constraint “FK_CAS_ClaimsAdjustment_Header835”. The conflict occurred in database “ERA835DB”, table “dbo.Header835”, column ‘TRANSACTIONID’.

The TRANSACTIONID Column in the Header table is set as Identity=True. The child table, CAS_ClaimsAdjustment has a column TransactionID that is FK to Header.TransactionID.

Why does DBContext.SaveChanges() seem to behave differently depending on how the same code is called?

 foreach (var file in Files)
  { 
          Parser parser = new Parser();
          parser.HandleFile(file);
  }


public class Parser
{

  public void HandleFile(string file)
  {
      using (Model.DbContext dbcontext)
    {
        foreach (var itemn in file)
        {
           Claims claim = new Claims();

            // ...

           dbcontext.Claims.Add(claim);
        }

        dbcontext.SaveChanges();

    }
  }


}
  • 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-17T04:31:35+00:00Added an answer on June 17, 2026 at 4:31 am

    I solved my problem. In my console application I was declaring my entities as “static”. Of course this did not work. Once I removed the static keyword everything was fine.

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

Sidebar

Related Questions

I have some code that creates a Process instance and later starts it. There's
I have a process that contains C# code, C++\CLI code and native c++ code.
So i have an application that creates like 2000 objects. For each object, it
i have a method that creates a Process calling a console app. double myProcess()
I have a method that takes a cgi object and creates a CGI::FormBuilder object.
I have a process in R that creates a bunch of objects, serializes them,
I have a VBA application that creates an instance of a COM object and
I have a command-line process that creates a PDF file from an HTML file
I have a process I run periodically on a background thread that receives changes
I have written a Windows service that spawns a separate process. This process creates

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.