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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:22:51+00:00 2026-06-16T15:22:51+00:00

Edit: I need help to rewrite these linq querys to SQL querys for highest

  • 0

Edit: I need help to rewrite these linq querys to SQL querys for highest possible performance.

I have a table with about 10 million rows. It consists of 7 columns including Id. First is Id, then three keys to “TradeObjectModel”, finally three integers keeping the different TradeObjectModels rating values. Like this:
enter image description here

When a user, eg To1Id (TradeObjectModel1 owner) with key 71 handles her ratings of other Trade objects only one row is sufficent for the current view.

My attempt to solve this looks like this(explanation below code sample):

IEnumerable<RatingListTriangleModel> allTriangleModels1 =
                this._ratingListTriangleRepository.All.Where(
                    ratingListRow =>
                    ratingListRow.To1Id == myTradeObject.TradeObjectId);
            var filteredallTriangleModels1 = from row in allTriangleModels1
                                             group row by row.To2Id into g
                                             select g.First();


            IEnumerable<RatingListTriangleModel> allTriangleModels2 =
                this._ratingListTriangleRepository.All.Where(
                    ratingListRow =>
                   ratingListRow.To2Id == myTradeObject.TradeObjectId);
            var filteredallTriangleModels2 = from row in allTriangleModels2
                                             group row by row.To3Id into g
                                             select g.First().

            IEnumerable<RatingListTriangleModel> allTriangleModels3 =
                this._ratingListTriangleRepository.All.Where(
                    ratingListRow =>
                   ratingListRow.To3Id == myTradeObject.TradeObjectId);

            var filteredallTriangleModels3 = from row in allTriangleModels3
                                             group row by row.To1Id into g
                                             select g.First();


            var fileredallTriangleModels =
                filteredallTriangleModels1.Union(filteredallTriangleModels2).Union(filteredallTriangleModels3).ToList();


            ViewBag.TriangleCount = fileredallTriangleModels.Count();

            foreach (var ratingListRow in fileredallTriangleModels)
            {
                //Find which one is my ad and set me as setter and their object as receiver
                if (ratingListRow.To1Id == customer.TradeObjectId)
                {
                    var ri = new TriangleViewModel(
                        customer.TradeObjectId,
                        this._customerRepository.FindTradeObjectId(ratingListRow.To2Id),
                        ratingListRow,
                        this._tradeobjectRepository.Find(ratingListRow.To2Id));

                    model.Models3.Add(ri);
                    continue;
                }

                if (ratingListRow.To2Id == customer.TradeObjectId)
                {
                    var ri = new TriangleViewModel(
                        customer.TradeObjectId,
                        this._customerRepository.FindTradeObjectId(ratingListRow.To3Id),
                        ratingListRow,
                        this._tradeobjectRepository.Find(ratingListRow.To3Id));

                    model.Models3.Add(ri);
                    continue;
                }

                if (ratingListRow.To3Id == customer.TradeObjectId)
                {
                    var ri = new TriangleViewModel(
                        customer.TradeObjectId,
                        this._customerRepository.FindTradeObjectId(ratingListRow.To1Id),
                        ratingListRow,
                        this._tradeobjectRepository.Find(ratingListRow.To1Id));
                    model.Models3.Add(ri);
                }
            }

First I get all rows where my object is on the first column, groups them to select only one and then continues to do the same with me on the second and third column. The ToList() here is just temporary for med to be able to run stopwatch on them, each of these takes 0-12 seconds. Then I join them and run through them all to create the model used by the webgrid in front-end code.

This causes two problems: 1. It takes much to long. and 2. If my tradeobject id is on more than one column I will get more than one row presenting more than one o the Tradeobject I’m interested in.

  • 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-16T15:22:53+00:00Added an answer on June 16, 2026 at 3:22 pm

    Try using Database Engine Tuning Advisor to see if adding/removing/changing the indices on your tables significantly improves the performance of the workload presented by your LINQ query.

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

Sidebar

Related Questions

I need to edit XML files on a small Linux box that we have
FULL EDIT: I urgently need to access a Microsoft SQL Server and read compressed
I need help with some rewrite rule Pretty much all my pages look like
I'm stuck on a problem and if possible I will need help from the
Need help with a wordpress problem. I need to edit the query.php to ONLY
i need help to edit this PHP script. Currently it looks for the most
I need help trying to create a link that submits an edit form. Let's
I need small help with jquery. EDIT: echo <li> ; echo $navi_menu->navi_name; echo <ul>;
Ok, so I have the following situation. I need to edit the PYTHONPATH dynamically
i need help with this 2 rewrite rules: RewriteEngine On RewriteBase / # folder/script.php?A=1&B=2

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.