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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:42:49+00:00 2026-05-25T23:42:49+00:00

I have a LINQ query which is searching a SQL table of around 250,000

  • 0

I have a LINQ query which is searching a SQL table of around 250,000 records and only searching on 2 fields. Both fields have been indexed but I find its still running rather slow.

Below is the code, can anyone suggest anything to help speed it up?

thanks

var qryN = (
    from bn in dbs.Uploads
    orderby bn.ID descending
    select new
    {

        ID = bn.ID,
        Serial = bn.serial_no,
        Manufacturer = bn.Mfgr,
        Model = bn.model,
        Code = bn.code,
        Qty = bn.qty,
        Description = bn.description,
        Comments = bn.comments,
        Location = bn.location,
        Price = bn.price,
        Email = "Register / Login for full details"
    });

if (dlType.Text != " " && dlType.Text != "")
{
    qryN = qryN.Where(bn => bn.Manufacturer == dlType.SelectedValue);
}

if (txtWord.Text != "")
{
    qryN = qryN.Where(bn => bn.Description.Contains(txtWord.Text));
    }

gvLoggedOff.DataSource =
    from p in qryN
    select new
    {
        p.ID, 
        p.Serial, 
        p.Manufacturer, 
        p.Model, p.Code, 
        p.Qty, 
        p.Description, 
        p.Comments, 
        p.Location, 
        p.Price, 
        p.Email
    };

gvLoggedOff.DataBind();    var qryN = (
    from bn in dbs.Uploads
    orderby bn.ID descending
    select new
    {

        ID = bn.ID,
        Serial = bn.serial_no,
        Manufacturer = bn.Mfgr,
        Model = bn.model,
        Code = bn.code,
        Qty = bn.qty,
        Description = bn.description,
        Comments = bn.comments,
        Location = bn.location,
        Price = bn.price,
        Email = "Register / Login for full details"
    });

if (dlType.Text != " " && dlType.Text != "")
{
    qryN = qryN.Where(bn => bn.Manufacturer == dlType.SelectedValue);
}

if (txtWord.Text != "")
{
    qryN = qryN.Where(bn => bn.Description.Contains(txtWord.Text));
    }

gvLoggedOff.DataSource =
    from p in qryN
    select new
    {
        p.ID, 
        p.Serial, 
        p.Manufacturer, 
        p.Model, p.Code, 
        p.Qty, 
        p.Description, 
        p.Comments, 
        p.Location, 
        p.Price, 
        p.Email
    };

gvLoggedOff.DataBind();
  • 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-25T23:42:50+00:00Added an answer on May 25, 2026 at 11:42 pm

    Two things:

    • Since you’re adding filters, move the projection (selecting into a new anonymous type) to the last line instead of the first, the DataSource line.
    • You’re ordering very early. Unless the queryable or the query analyzer are smart enough to analyze and optimize this, the database will have to order 250,000 rows before it starts filtering. Move the ordering to as late as you can, probably just before the projection takes place.

    Here’s a short attempt at modifying your sample:

    var qryN = dbs.Uploads.AsQueryable();
    
    if (dlType.Text != " " && dlType.Text != "")
        qryN = qryN.Where(bn => bn.Mfgr == dlType.SelectedValue);
    
    if (txtWord.Text != "")
        qryN = qryN.Where(bn => bn.description.Contains(txtWord.Text));
    
    gvLoggedOff.DataSource = qryN.OrderByDescending(bn => bn.ID)
        .Select(bn => new { 
            bn.ID, Serial = bn.serial_no, Manufacturer = bn.Mfgr,
            Model = bn.model, Code = bn.code, Qty = bn.qty,
            Description = bn.description, Comments = bn.comments,
            Location = bn.location, Price = bn.price,
            Email = "Register / Login for full details" });
    
    gvLoggedOff.DataBind();
    

    Since this was accepted as an answer: Steven’s answer about text searching is probably also applicable in some situations. Full text searching can drain performance like you wouldn’t believe.

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

Sidebar

Related Questions

Strange performance outcome, I have a LINQ to SQL query which uses several let
I have the following Linq to SQL query, in which I'm trying to do
I have the following LINQ query which uses NHibernate against a SQL Server backed
I have a LINQ to SQL query which produces an object of type {System.Data.Linq.DataQuery}.
In my WPF app I have implemented LINQ to SQL query which populates an
I have a LINQ query which returns IEnumerable<List<int>> but i want to return only
I have a LINQ query which results an array of Job records. Due to
I have a linq query which presents data that is present in CustomersRecord Table
I have a LINQ TO SQL query which retrieves all the users along with
I have Linq to SQL query which return one field with Url and I

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.