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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:11:31+00:00 2026-06-06T02:11:31+00:00

I have a web application (ASP.NET 4.0 in c#) and I am building a

  • 0

I have a web application (ASP.NET 4.0 in c#) and I am building a pseudo Adhoc component. This component allows the user to select from a list of predetermined categories (Car Make, Care Model, Car Accessories, etc). The user can select as many categories as they wish and then they press a “Filter” button which will take the categories that are selected and send them to a new form with the options of each category. Each category can have multiple options.

Example:
User selects Car Color, Car accessories.

Filter page shows a form with a drop down pre-populated with colors for Car Color. Form shows a check box for Satellite Radio, another check box for Leather Interior, etc. All of these values are predefined. Once a user specifies all of the items they can filter upon, I am using Linq to query the database. As it is now, the Linq query is against a View that currently holds 14 Left Outer Joins and, if not filtered at all, returns over 30,000 rows.

I am using dynamic linq to query to database link so:

var data = CMS.Model.Adhoc.GetData().AsQueryable(); //must be AsQueryablefor Dynamic Linq to function

    public static List<ViewADHOCContractInfo> GetData()
    {
        PortalDataContext db = new PortalDataContext(AuthenticatedUser.ConnectionString);

        return db.ViewADHOCInfos.Select(x=>x).Distinct().ToList();
    }

NOTE that GetData() is returning all rows and all columns of the result set, which I do not think is the most efficient way to do this, more on that at the bottom.

From there I am performing a FOREACH statement on the filters that were sent in, and minimizing the result set on each iteration like so (abbreviated):

foreach (Filters filter in filters.OrderBy(x=>x.strOrderNumber))
        {
            SanatizeFilter(filter.strFilter,filter);
            if (filter.strValue != string.Empty && filter.strValue != null)
            {
                if (filter.strOperator == "Contains")
                {
                    data = data.Where(filter.strFilter + "!= NULL and " + filter.strFilter + ".Contains(@0)", filter.strValue).
                        Select(x => x).ToList().AsQueryable();
                }
                else
                {
                    data = data.Where(filter.strFilter + FormatOperator(filter.strOperator) + "@0", filter.strValue).
                        Select(x => x).ToList().AsQueryable();


                }
            }
        }

All of this works fine, however it is slow. My first question is, how can I use Linq to cut this down a bit. I have tried a few ways to pull only the data that comes from the filter into the variable “data” as a way to pre-populate, however I can’t get that to work with the .AsQueryable(). I would like to be able to get the column identifiers from the filter objects and select only those from the database so that I don’t have to deal with all of the overhead, but I can’t find a solution that will allow me to do this, any ideas?

Second Question is right now this is all in a view in the database, would it be faster/more efficient to move it to a function or a stored procedure? Can Linq interact with a stored procedure?

Thanks in advance

  • 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-06T02:11:36+00:00Added an answer on June 6, 2026 at 2:11 am

    Well, your question can be split in two parts:

    1) Is my linq-2-sql approach good

    2) Is my database approach good

    The first part can be solved by profiling your SQL that is send to the database. This will show you what query/queries are actually executed. As you can see in the comments, by using ToList() early in your approach, this might be far from optimal. Databases are very good in filtering and handling large sets of data. So let them do what they are best at!

    Now the second part of your question is about the view. Would it be faster to use a stored procedur etc? To answer a part of your question: yes, Linq-2-sql can use a stored procedure as well. But if you are using the stored to procedure to retrieve too much data, it will still be slow. This is the DBA-part of the story. Perhaps a few indexes on the base tables will be sufficient. Another approach can be to add a clustered index to your view which in turn materializes it.

    I would advise you first to deal with the linq-2-sql part: make sure that the sql that is actually excecuted is set-based and all of your filtering is being done in the database. If it is still too slow, move on to the database layer and see what you can improve there.

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

Sidebar

Related Questions

I have jQuery based template from themeforest and i building on this ASP.NET Web
I building a web application in ASP.NET 3.5 and C#. I have a method
I am new to ASP.NET and building a financial web application. I have a
I'm building an ASP.net application using Visual Studio Web Developer 2010 Express and have
We have a Web application (ASP.NET) which displays in some page links to miscellaneous
I have a Web Application (ASP.NET C# for .NET 3.5) that uses the Session
I have a web application on ASP.NET (C#) that has some precompiled components. I've
I have a web application in Asp.Net. I've created my master page and inside
i have developed a web application asp.net C#. on a button click i am
I have a web application developed in ASP.NET 2.0, deployed in a data center.

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.