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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:17:58+00:00 2026-06-02T09:17:58+00:00

I retrieve data from two different repositories: List<F> allFs = fRepository.GetFs().ToList(); List<E> allEs =

  • 0

I retrieve data from two different repositories:

        List<F> allFs = fRepository.GetFs().ToList();
        List<E> allEs = eRepository.GetEs().ToList(); 

Now I need to join them so I do the following:

        var EFs = from c in allFs.AsQueryable()
                        join e in allEs on c.SerialNumber equals e.FSerialNumber
                        where e.Year == Convert.ToInt32(billingYear) && 
                        e.Month == Convert.ToInt32(billingMonth)
                        select new EReport
                        {
                            FSerialNumber = c.SerialNumber,
                            FName = c.Name,
                            IntCustID = Convert.ToInt32(e.IntCustID),
                            TotalECases = 0,
                            TotalPrice = "$0"
                        };

How can I make this LINQ query better so it will run faster? I would appreciate any suggestions.

Thanks

  • 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-02T09:18:00+00:00Added an answer on June 2, 2026 at 9:18 am

    Unless you’re able to create one repository that contains both pieces of data, which would be a far preferred solution, I can see the following things which might speed up the process.

    1. Since you’r always filtering all E’s by Month and Year, you should do that before calling ToList on the IQueryable, that way you reduce the number of E’s in the join (probably considerably)
    2. Since you’re only using a subset of fields from E and F, you can use an anonymous type to limit the amount of data to transfer
    3. Depending on how many serialnumbers you’re retrieving from F’s, you could filter your E’s by serials in the database (or vice versa). But if most of the serialnumbers are to be expected in both sets, that doesn’t really help you much further

    Reasons why you might not be able to combine the repositories into one are probably because the data is coming from two separate databases.

    The code, updated with the above mentioned points 1 and 2 would be similar to this:

    var allFs = fRepository.GetFs().Select(f => new {f.Name, f.SerialNumber}).ToList();
    
    int year = Convert.ToInt32(billingYear);
    int month = Convert.ToInt32(billingMonth);
    
    var allEs = eRepository.GetEs().Where(e.Year == year && e.Month == month).Select(e => new {e.FSerialNumber, e.IntCustID}).ToList();
    
    
    var EFs = from c in allFs
        join e in allEs on c.SerialNumber equals e.FSerialNumber
        select new EReport
        {
            FSerialNumber = c.SerialNumber,
            FName = c.Name,
            IntCustID = Convert.ToInt32(e.IntCustID),
            TotalECases = 0,
            TotalPrice = "$0"
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to retrieve data from two tables. the first is a list of
How to retrieve data from two tables whose column names are the same?
I'm trying to retrieve data from two tables, 'publisher' and 'magazine'. I'm listing the
I have two XML sources to retrieve data from. I want to use them
I need to retrieve data from MsAccess/SQL Server (two separate projects in which I
I am attempting to retrieve data from two tables and echo the results out,
I retrieve data from db like that: select * from MOVIE_COMMENT where USER_ID =
I'd like to retrieve data from a specific webpage by using urllib library. The
Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I'm attempting to retrieve data from a SolarWinds network performance database (MS SQL 2005)

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.