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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:45:19+00:00 2026-05-30T20:45:19+00:00

I return a List from a Linq query, and after it I have to

  • 0

I return a List from a Linq query, and after it I have to fill the values in it with a for cycle.
The problem is that it is too slow.

var formentries = (from f in db.bNetFormEntries
            join s in db.bNetFormStatus on f.StatusID.Value equals s.StatusID into entryStatus
            join s2 in db.bNetFormStatus on f.ExternalStatusID.Value equals s2.StatusID into entryStatus2
            where f.FormID == formID
            orderby f.FormEntryID descending
            select new FormEntry
            {
                FormEntryID = f.FormEntryID,
                FormID = f.FormID,
                IPAddress = f.IpAddress,
                UserAgent = f.UserAgent,
                CreatedBy = f.CreatedBy,
                CreatedDate = f.CreatedDate,
                UpdatedBy = f.UpdatedBy,
                UpdatedDate = f.UpdatedDate,
                StatusID = f.StatusID,
                StatusText = entryStatus.FirstOrDefault().Status,
                ExternalStatusID = f.ExternalStatusID,
                ExternalStatusText = entryStatus2.FirstOrDefault().Status
            }).ToList();

and then I use the for in this way:

for(var x=0; x<formentries.Count(); x++)
{
    var values = (from e in entryvalues
                where e.FormEntryID.Equals(formentries.ElementAt(x).FormEntryID)
                select e).ToList<FormEntryValue>();
    formentries.ElementAt(x).Values = values;
}
return formentries.ToDictionary(entry => entry.FormEntryID, entry => entry);

But it is definitely too slow.
Is there a way to make it faster?

  • 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-30T20:45:21+00:00Added an answer on May 30, 2026 at 8:45 pm

    For what I see, you are iterating trough formentries 2 more times without reason – when you populate the values, and when you convert to dictionary.

    If entryvalues is a database driven – i.e. you get them from the database, then put the value field population in the first query.

    If it’s not, then you do not need to invoke ToList() on the first query, do the loop, and then the Dictionary creation.

    var formentries = from f in db.bNetFormEntries
                    join s in db.bNetFormStatus on f.StatusID.Value equals s.StatusID into entryStatus
                    join s2 in db.bNetFormStatus on f.ExternalStatusID.Value equals s2.StatusID into entryStatus2
                    where f.FormID == formID
                    orderby f.FormEntryID descending
                    select new FormEntry
                    {
                        FormEntryID = f.FormEntryID,
                        FormID = f.FormID,
                        IPAddress = f.IpAddress,
                        UserAgent = f.UserAgent,
                        CreatedBy = f.CreatedBy,
                        CreatedDate = f.CreatedDate,
                        UpdatedBy = f.UpdatedBy,
                        UpdatedDate = f.UpdatedDate,
                        StatusID = f.StatusID,
                        StatusText = entryStatus.FirstOrDefault().Status,
                        ExternalStatusID = f.ExternalStatusID,
                        ExternalStatusText = entryStatus2.FirstOrDefault().Status
                    };
    
    var formEntryDictionary = new Dictionary<int, FormEntry>();
    
    foreach (formEntry in formentries)
    {
        formentry.Values = GetValuesForFormEntry(formentry, entryvalues);
        formEntryDict.Add(formEntry.FormEntryID, formEntry);
    }
    
    return formEntryDictionary;
    

    And the values preparation:

    private IList<FormEntryValue> GetValuesForFormEntry(FormEntry formEntry, IEnumerable<FormEntryValue> entryValues)
    {
        return (from e in entryValues
                        where e.FormEntryID.Equals(formEntry.FormEntryID)
                        select e).ToList<FormEntryValue>();
    }
    

    You can change the private method to accept only entryId instead the whole formEntry if you wish.

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

Sidebar

Related Questions

I have a VB .Net linq query that I want to return values from
I have a LINQ query that populates a list of designers. Since I am
I have a query in linqtosql that returns a LabelNumber: var q = from
I have a linq query where I'm trying to return all MlaArticles that are
I have a LINQ query which returns IEnumerable<List<int>> but i want to return only
I'm creating a linq query to get some data that will return a list
I have a linq query that returns a list and the result looks like
I have a situation where i want to return List<> from this function public
Isn't there a way with Hibernate to return a list of (primitive) values from
I am trying to use LINQ to return a list of tasks that are

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.