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

The Archive Base Latest Questions

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

I was hoping I could get some help optimizing the following data retrieval. Here

  • 0

I was hoping I could get some help optimizing the following data retrieval. Here is the use case. I want to display a list of translators (suppliers) in a Telerik ASP.NET MVC grid. These translators have rates (or pricing schemes) by language pair. There are less 400 translators in this database. I want to display all of them initially, but let users filter by languages they translate. There is a supplier (translator) table, language pair table (with FK for source and target language), and language table.

Here is what I have but it is slow. The primary reason is that for each supplier, I need to get every unique language they translate (source and target language). I don’t know how to do that without a ForEach. I’m not even sure how I could do this in SQL without a while, temp table, or a cursor.

public List<tblSupplier> GetApprovedSuppliers()
{
    var query = from s in db.tblSuppliers
                join c in db.tblCountryLists on s.SupplierCountry equals c.CountryID into g1
                from c in g1.DefaultIfEmpty()
                select new
                {
                    SupplierID = s.SupplierID,
                    SupplierName = s.CompanyName == null ? s.SupplierFirstName + " " + s.SupplierLastName : s.CompanyName,
                    SupplierEmails = s.SupplierEmails,
                    SupplierType = s.SupplierType,
                    Country = c.Countryname
                };

    List<tblSupplier> list = query.ToList().ConvertAll(s => new tblSupplier
    {
        SupplierID = s.SupplierID,
        SupplierName = s.SupplierName,
        SupplierEmails = s.SupplierEmails,
        SupplierType = s.SupplierType,
        Country = s.Country
    }).OrderBy(s => s.SupplierName).ToList();

    list.ForEach(s => s.Languages = this.GetLanguages(s.SupplierID));

    return list;
}

public string GetLanguages(int supplierID)
{
    var query = (from ps in db.tblSupplierPricingSchemes
                    join lp in db.tblLangPairs on ps.PSLangPairID equals lp.ProductID
                    join sl in db.tblLanguages on lp.SourceLanguageID equals sl.LanguageID
                    where ps.SupplierID == supplierID
                    select sl.LanguageDesc)
                .Union
                (from ps in db.tblSupplierPricingSchemes
                    join lp in db.tblLangPairs on ps.PSLangPairID equals lp.ProductID
                    join tl in db.tblLanguages on lp.TargetLanguageID equals tl.LanguageID
                    where ps.SupplierID == supplierID
                    select tl.LanguageDesc);        

    return string.Join(", ", query);
}

Any help is appreciated.

Thanks,
Steve

  • 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-26T23:33:42+00:00Added an answer on May 26, 2026 at 11:33 pm

    You must reduce number of queries. If you have correctly defined model you can start by using Include. If you don’t have correctly defined model with navigation properties you can replace multiple calls of GetLanguages to single call and reconstruct dataset in your application. To replace multiple calls of GetLanguages change message signature to:

    public Dictionary<id, string> GetLanguages(int[] suppplierIds)
    

    and replace ps.SupplierID == supplierID with supplierIds.Contains(ps.SupplierID)` – you need at least EFv4 to make this work. So the result should look like:

    public Dictionary<id, string> GetLanguages(int[] supplierIds)
    {
        var query = (from ps in db.tblSupplierPricingSchemes
                        join lp in db.tblLangPairs on ps.PSLangPairID equals lp.ProductID
                        join sl in db.tblLanguages on lp.SourceLanguageID equals sl.LanguageID
                        where ps.SupplierID == supplierID
                        select new { ps.SupplierID, sl.LanguageDesc })
                    .Union
                    (from ps in db.tblSupplierPricingSchemes
                        join lp in db.tblLangPairs on ps.PSLangPairID equals lp.ProductID
                        join tl in db.tblLanguages on lp.TargetLanguageID equals tl.LanguageID
                        where ps.SupplierID == supplierID
                        select new { ps.SupplierID, tl.LanguageDesc }); 
    
        query = from x in query
                group x by x.SupplierID into g
                select g; 
    
        return query.ToDictionary(x => x.Key, x => String.Join(", ", x));
    }
    

    No you must only use this method like:

    Dictionary<int, string> languages = GetLanguages(list.Select(s => s.SupplierID));
    list.ForEach(s => s.Languages = languages[s.SupplierID]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hoping to get some help here. I have locations on a database that I
I was hoping I could get some help with a Query I am trying
I'm hoping to get some help with this weird problem. We're running the Jacorb
I have been playing with generics and was hoping I could get some feedback
I am hoping to get some help solving a problem that I'm sure many
Im using the .NET framework 1.1 and Im hoping someone could help me implement
I have a problem, and was hoping I could rely on some of the
I am relatively new to web development, and I was hoping I could get
I was hoping to get some good ideas as to what might be causing
I was hoping someone that is good with math and loops could help me

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.