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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:02:00+00:00 2026-05-10T22:02:00+00:00

Does anyone have some good information on the usage of the .SaveChanges() method? I

  • 0

Does anyone have some good information on the usage of the .SaveChanges() method?

I am experiencing a variety of issues when attempting to use the .SaveChanges() method on my data context object. I am taking data from an existing data source, creating the appropriate EntityFramework/DataService objects, populating those created objects with data, adding those objects to the context and then saving that data by calling .SaveChanges.

The scenarios I’ve come up with (and the problems associated with them) are as such … In each scenario I have a foreach loop that is taking data from rows in a DataTable and generating the objects, attaching them to the context as they go. (note: three objects a ‘member’ and two ‘addresses’ that are attached via a SetLink call) – basically this is a conversion tool to take data from one data store and massage it into a data store that is exposed by Data Services.

  • Call .SaveChanges() without any parameters once at the end of the foreach loop (i.e. outside the loop)
    • OutOfMemory error about 1/3 of the way (30,000 out of 90,000 saves) – not sure how that is happening though as each save item is a seperate SQL call to the database, what is there to run out of memory on?
  • Call .SaveChanges() without any parameters once per loop
    • This works, but takes absolutly forever (8 hours for 90,000 saves)
  • Call .SaveChanges(SaveChangesOption.Batch) once at the end of the foreach loop
    • Same OutOfMemory error, but without any saves to the database
  • Call .SaveChanges(SaveChangesOption.Batch) once per loop
    • 404 not found error
  • Call .SaveChanges(SaveChangesOption.Batch) once per 10 loops
    • 400 Bad Request error (occassionally)
    • OutOfMemory after a number of itterations
  • A number of random attempts to create the context once per loop, or have it as a variable at the start of the loop or have it as a private member variable that is available.
    • Differing results, unable to quantify, none really that good

What is the prefered method of calling .SaveChanges() from a client object when doing a large data load like this? Is there something I’m not getting about how .SaveChanges() works? Can anyone provide more details on how once should be utilizing this function and what (if any) are the limitations to saving data via Data Services? Are there any best practices around the .SaveChanges() method call? Is there any particularly good documentation on the .SaveChanges() method call?

  • 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. 2026-05-10T22:02:01+00:00Added an answer on May 10, 2026 at 10:02 pm

    I have no big experience in using EntityFramework (just some random experiment), have you tried calling .SaveChanges() every n iterations?

    I mean something like this:

    int i = 0; foreach (var item in collection) {     // do something with your data     if ((i++ % 10) == 0)         context.SaveChanges(); } context.SaveChanges(); 

    I know it’s ugly, but it’s the first possible solution i came up with.

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

Sidebar

Ask A Question

Stats

  • Questions 84k
  • Answers 84k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I ended up using awk to do this. Here is… May 11, 2026 at 5:04 pm
  • Editorial Team
    Editorial Team added an answer when you do the math, you lose the leading zeros,… May 11, 2026 at 5:04 pm
  • Editorial Team
    Editorial Team added an answer C++ notes a distinction between declaring and defining. bands is… May 11, 2026 at 5:04 pm

Related Questions

Does anyone have any good starting points for me when looking at making web
I'm about to start a project that requires XML messages to be sent between
I've been running up against a problem with Java Swing + my Wacom Graphire
I am building a web app where I need to get all the images

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.