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

  • Home
  • SEARCH
  • 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 265963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:48:54+00:00 2026-05-11T22:48:54+00:00

I’ve got an performance issue in my application using a MSSQL DB. I have

  • 0

I’ve got an performance issue in my application using a MSSQL DB. I have a Database Architecture with the following tables:

  • Job (Primary Key: Job ID),
  • Jobitem(Primary Key: Jobitem ID, Foreign Key: Job ID),
  • Job2Property (Foreign Key: Job ID <-> Property ID),
  • Jobitem2Property(Foreign Key: Jobitem ID <-> Property ID),
  • Property (Primary Key: Property ID).

Now when I want to delete a Job, I first have to delete its Jobitems, then the Job2Property references and last I can delete the Properties and the Job itself. For the Jobitems, I need to delete the Jobitem2Property references first as well, followed by its Properties and the Jobitem itself.

This is the method to delete the jobs:

public void Delete(List<Job> jobsToDelete)
{
    var jobitemsToDelete = new List<Jobitem>();

    // Gather references to jobitems to delete
    foreach (Job job in jobsToDelete) {
        List<Jobitem> jobitems =
            (from ji in job.Jobitems.Values
             select ji).ToList();

        jobitemsToDelete.AddRange(jobitems);
    }

    // first the related jobitems and the properties have to be deleted
    PropertyManager.Instance.Delete(jobsToDelete);        
    Delete(jobitemsToDelete);

    dbc.Job.DeleteAllOnSubmit(jobsToDelete);
    dbc.SubmitChanges();

    // Remove Job from dictionary to avoid using Refresh()
    foreach (Job job in jobsToDelete) {
        Jobs.Remove(job.Id);
    }
}

The following method deletes the jobitems:

public void Delete(List<Jobitem> jobitemsToDelete)
{
    PropertyManager.Instance.Delete(jobitemsToDelete);

    dbc.Jobitem.DeleteAllOnSubmit(jobitemsToDelete);
    dbc.SubmitChanges();
}

And finally the method to delete the Properties:

public void Delete(List<Job> jobsToDelete)
{
    List<Property> propsToDelete = new List<Property>();

    foreach (Job job in jobsToDelete) {
        if (JobProperties.ContainsKey(job.Id))
            propsToDelete.AddRange(JobProperties[job.Id]);
    }

    List<Job2Property> j2pToDelete =
        (from p in propsToDelete
         select p.Job2Property.First()).ToList();

    dbc.Job2Property.DeleteAllOnSubmit(j2pToDelete);
    dbc.Property.DeleteAllOnSubmit(propsToDelete);
    dbc.SubmitChanges();
}

The method to delete jobitem properties looks exactly the same with the exception that it takes List<Jobitem> as parameter.

Now the performance of deletion is really bad. For a single Job, it takes around 3 seconds. When I delete 10 rows, it takes 13 to 14 seconds. Before I had the Property and XYZ2Property tables, it would take less than a second.

How can I optimize the speed of this?
Profiling the application with ProfileSharp I came to the conclusion that the delete function eats about 17% of the total processing time of the application (that’s 9405781250 units of time), whereas the call to dbc.SubmitChanges() in the last method to delete properties seems to take most of this time (it states 1475%, but that seems to be a bug of ProfileSharp. Rather, it eats up most of this 17% I guess).

Here’s a picture of the profile.

Can I do something about this?

  • 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-11T22:48:54+00:00Added an answer on May 11, 2026 at 10:48 pm

    What database is this? Anyway, I wouldn’t have the responsibility of deleting all those jobs, jobitems, and jobproperties and what not in the code, but in the database instead. For foreign keys, you can specify a cascading delete, which means that if you delete a certain job, all corresponding jobitems and properties are also deleted. It saves you a lot of code, and it is less error prone. Look it up. In SQL Server Management Studio it is right under the Foreign Key Relationships editor.

    It’s probably going to be much faster as well, since you don’t have to do select queries to retrieve all the corresponding jobitems and properties. So in short, you’d get less code, less bugs, and improved performance.

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

Sidebar

Ask A Question

Stats

  • Questions 132k
  • Answers 132k
  • 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 This will help you: Compiler, the image is pretty simple… May 12, 2026 at 6:25 am
  • Editorial Team
    Editorial Team added an answer SELECT person.name, person.age, ( SELECT address.streetAddress, address.town, address.postcode FROM Address… May 12, 2026 at 6:25 am
  • Editorial Team
    Editorial Team added an answer Consider using Django's json lib, which is included with GAE.… May 12, 2026 at 6:25 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.