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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:20:36+00:00 2026-05-31T04:20:36+00:00

I am populating my database from online data using the loop like (simplified, with

  • 0

I am populating my database from online data using the loop like (simplified, with no error checking):

foreach (var catalog in catalogs)
{
   var result = Items(catalog, state, context);
   while (result != null)
   {
      result.ForEach(r => context.DbContext.Items.Add(r));
      context.DbContext.SaveChanges();
      result = Items(catalog, state, context);
   }
}                  

Code takes some time to get XML response from the server and to decode it into XElement, using XElement.Load on response stream. It is decoded into a list of items which contains max 50 items – that is what I requested from the server in each loop pass. That chunk gets saved to a table right away because of SaveChanges call..

8/10 of the loop time is spent either on adding items to DbContext or in SaveChanges call or on both. Communication with the remote server and decoding response XML into a list of entities is 2/10.

How can I increase the efficiency of storing data into the database, while still staying with EF?

I am aware that I can bulk-load the database from XML, but that will force me to figure out SQL statements that I need to write, because several related tables get updated with the SaveChanges call above, and so I start losing the advantages of using EF.

  • 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-05-31T04:20:38+00:00Added an answer on May 31, 2026 at 4:20 am

    In short: You cannot speed your insertion process with pure EF because EF has very poor performance for bulk / batch data processing. You have two problems:

    • Adding entity to context has some costs and this costs increases with every entity already present in the context. To avoid this you can try to call SavaChanges after each call to Addor even try to use new context for every batch or even every call to Add.
    • EF makes a separate database roundtrip for every record you want to insert, update or delete so it generally doesn’t matter how often do you call SaveChanges. Avoiding this is mostly possible only when using direct SQL and creating single SqlCommand executing all inserts at once.

    If you want to increase performance use direct SQL.

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

Sidebar

Related Questions

inside mvc3 application i'm populating dropdownlist from database using following query. getting error on
I've asked before about populating the list view with data from the database. Now
In my application I'am populating a dropdownlist from database using ADO Entity Framework, after
I'm using an AutoCompleteExtender in ASP.NET/C# to retrieve data from my database, along with
I am populating an array of hashes from the database and what I get
i have a dropdownlist that populates from the sql server database. populating the list
I have a Populater class for populating a database with random data. I would
im populating the data in the combo box using dataset tables...with some table name..now
How would I go about populating a database from info in a csv file
I have TreeView Populating from Database And I am Trying to detect the user

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.