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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:22:50+00:00 2026-06-03T01:22:50+00:00

I am currently using Entity Framework 4.2 with Code First. I currently have a

  • 0

I am currently using Entity Framework 4.2 with Code First. I currently have a Windows 2008 application server and a database server running on Amazon EC2. The application server has a Windows Service installed that runs once per day. The service executes the following code:

// returns between 2000-4000 records
var users = userRepository.GetSomeUsers();

// do some work

foreach (var user in users)
{
    var userProcessed = new UserProcessed { User = user };
    userProcessedRepository.Add(userProcessed);
}

// Calls SaveChanges() on DbContext
unitOfWork.Commit();

This code takes a few minutes to run. It also maxes out the CPU on the application server. I have tried the following measures:

  • Remove the unitOfWork.Commit() to see if it is network related when the application server talks to the database. This did not change the outcome.
  • Changed my application server from a medium instance to a high CPU instance on Amazon to see if it is resource related. This caused the server not to max out the CPU anymore and the execution time improved slightly. However, the execution time was still a few minutes.

As a test I modified the above code to run three times to see if execution time for the second and third loop using the same DbContext. Every consecutive loop took longer to run that the previous one but that could be related to using the same DbContext.

Am I missing something? Is it really possible that something as simple as this takes minutes to run? Even if I don’t commit to the database after each loop? Is there a way to speed this up?

  • 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-03T01:22:52+00:00Added an answer on June 3, 2026 at 1:22 am

    Entity Framework (as it stands) isn’t really well suited to this kind of bulk operation. Are you able to use one of the bulk insert methods with EC2? Otherwise, you might find that hand-coding the T-SQL INSERT statements is significantly faster. If performance is important then that probably outweighs the benefits of using EF.

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

Sidebar

Related Questions

I am currently using ASP.NET MVC and Entity Framework Code First using the repository
Using the Entity Framework Code First paradigm I have defined the following objects and
I'm currently developing an app using ASP.NET MVC3 and Entity Framework 4.1 Code First
We have a project using Entity Framework 4.1 Code First for data storage. It
I am using Entity Framework code first and ASP.NET MVC 3. I have the
I am using Entity Framework Code First to create a database table. My model
I am using entity framework 4.1 code first. I have a GrantApplication class: public
I'm using the Entity Framework 4 code first approach to design my database in
I'm using Entity Framework Code First and whilst I have working code, I'm having
I'm currently using Entity Framework and am running into this issue: The relationship between

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.