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

The Archive Base Latest Questions

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

In a bigger project we decided to use Linq2Sql in the web-services (WCF). We

  • 0

In a bigger project we decided to use Linq2Sql in the web-services (WCF). We ‘quickly’ found out that after some data has been added (through a small console app importing customer data) the web-service slowed down – apperantly for the lifetime duration of that app.

Every time we restarted the app it seemingly imported data fast in the beginning, and then slowing down after maybe 10-15 minutes of import.

I decided to try to just create a sample app mimicking small parts of our main app.

  • I have to add, we decided to leave out Linq2Sql in the web services replacing them with reqular sqlcommand/SqlConnection etc.

Do anyone have a clue as to what this slowing down of an app might be caused by?

Here’s the code for the “minimized” app mimicking some database queries:

App including SQL statements to create the tables:

using System;
using System.Collections.Generic;
using System.Linq;

using System.Text;

namespace Linq2SqlTest
{
    class Program
    {
        /*
         * USE [Linq2SqlTest]
            GO
            SET ANSI_NULLS ON
            GO
            SET QUOTED_IDENTIFIER ON
            GO
            CREATE TABLE [dbo].[Adresse](
                [id] [int] IDENTITY(1,1) NOT NULL,
                [person_id] [int] NOT NULL,
                [Gate] [nvarchar](50) NOT NULL,
                [Poststed] [nvarchar](50) NOT NULL,
                [By] [nvarchar](50) NOT NULL,
             CONSTRAINT [PK_Adresse] PRIMARY KEY CLUSTERED 
            (
                [id] ASC
            )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
            ) ON [PRIMARY]

            GO
            ALTER TABLE [dbo].[Adresse]  WITH CHECK ADD  CONSTRAINT [FK_Adresse_Person1] FOREIGN KEY([person_id])
            REFERENCES [dbo].[Person] ([id])
            GO
            ALTER TABLE [dbo].[Adresse] CHECK CONSTRAINT [FK_Adresse_Person1]
         * 
         * 
         * USE [Linq2SqlTest]
            GO
            SET ANSI_NULLS ON
            GO
            SET QUOTED_IDENTIFIER ON
            GO
            CREATE TABLE [dbo].[Items](
                [ItemID] [int] IDENTITY(1,1) NOT NULL,
                [ItemNumber] [nchar](10) NOT NULL,
                [PersonID] [int] NOT NULL,
                [name] [nvarchar](50) NULL,
             CONSTRAINT [PK_Items] PRIMARY KEY CLUSTERED 
            (
                [ItemID] ASC
            )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
            ) ON [PRIMARY]

            GO
            ALTER TABLE [dbo].[Items]  WITH CHECK ADD  CONSTRAINT [FK_Items_Person] FOREIGN KEY([PersonID])
            REFERENCES [dbo].[Person] ([id])
            GO
            ALTER TABLE [dbo].[Items] CHECK CONSTRAINT [FK_Items_Person]

         *
         * USE [Linq2SqlTest]
                GO
                SET ANSI_NULLS ON
                GO
                SET QUOTED_IDENTIFIER ON
                GO
                CREATE TABLE [dbo].[Person](
                    [id] [int] IDENTITY(1,1) NOT NULL,
                    [name] [nvarchar](50) NOT NULL,
                    [AddedDate] [datetime] NOT NULL,
                    [ssn] [nvarchar](50) NOT NULL,
                 CONSTRAINT [PK_Person] PRIMARY KEY CLUSTERED 
                (
                    [id] ASC
                )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
                ) ON [PRIMARY]

         */

        public static Random randomizer = new Random();

        public static String GenerateName()
        {
            int nLetterCount = (randomizer.Next() % 5) + 3;

            String s = "";
            for (int i = 0; i < nLetterCount;i++)
            {
                int r = (randomizer.Next() % 26)+97;
                s += Convert.ToChar(r);
            }
            return s;
        }
        public static String GenerateFullname()
        {
            String Fullname = "";
            int nNameCount = randomizer.Next() % 3;
            nNameCount++;
            while (nNameCount>0)
            {
                if (Fullname.Length == 0)
                    Fullname = GenerateName();
                else
                    Fullname += " " + GenerateName();
                nNameCount--;
            }
            return Fullname;
        }
        static void Main(string[] args)
        {
            DatabaseDataContext db = new DatabaseDataContext();

            for (int i = 0; i < 300000;i++ )
            {
                int personid = randomizer.Next() % 100;
                Person p = db.Persons.FirstOrDefault(_p=> _p.ssn == personid.ToString());
                if (p == null)
                {
                    p = new Person();
                    p.name = GenerateFullname();
                    p.ssn = personid.ToString();
                    p.AddedDate = DateTime.Now;
                    db.Persons.InsertOnSubmit(p);
                    db.SubmitChanges();
                    Adresse a = new Adresse();
                    a.person_id = p.id;
                    a.Gate = GenerateFullname();
                    a.Poststed = GenerateName();
                    a.By = GenerateName();
                    db.Adresses.InsertOnSubmit(a);
                    db.SubmitChanges();
                    int jj = randomizer.Next() % 10 + 1;
                    for (int j = 0; j < jj; j++)
                    {
                        Item item = new Item();
                        item.ItemNumber = randomizer.Next().ToString();
                        item.PersonID = p.id;
                        db.Items.InsertOnSubmit(item);
                        db.SubmitChanges();
                    }
                }
                else
                {
                    int jj = randomizer.Next() % 10 + 1;
                    for (int j = 0; j < jj; j++)
                    {
                        int number = randomizer.Next();
                        Item item = db.Items.FirstOrDefault(_i => _i.ItemNumber == number.ToString());
                        if (item == null)
                        {
                            item = new Item();
                            item.ItemNumber = number.ToString();
                            item.PersonID = p.id;
                            db.Items.InsertOnSubmit(item);
                        }
                        else
                        {
                            item.ItemNumber = randomizer.Next().ToString();
                        }
                        db.SubmitChanges();
                    }
                }
                Console.WriteLine("\r" + i + "   ");
            }
        }
    }
}
  • 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-28T22:56:03+00:00Added an answer on May 28, 2026 at 10:56 pm

    I found out how to fix the problem. Some of the data was already “preloaded” (lazy loading?), and this wasn’t disabled. Thus if you want control over what LINQ should do, and NOT do “behind the scenes”, you should disable this feature.

    DatabaseContext.DeferredLoadingEnabled = false;
    

    Rookie mistake, sad to say 😐

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

Sidebar

Related Questions

I have decided to use IoC principles on a bigger project. However, i would
i am new in project for company that have bigger enterprise/accounting system based on
On a new project I have started, XCode has decided that it will compile
I was recently having some issues with a bigger project, but in an effort
I'm working on a bigger project atm, but I made this simple example to
Is there a native c++ variable type that's bigger than a double? float is
I had a problem while hacking a bigger project so I made a simpel
I copied a part of a bigger project i'm working on, I didn't wrote
I have this problem in a bigger Project...... so I set up a 'Testpoject'
I have a project in C#, WindowsForms and I created a panel that contains

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.