tolist on "sometable" right at the start. this is pulling the entire database table, with all rows and all columns, into memory and then performing all of the subsequent operations via linq-to-objects on that in-memory data structure.
not only are you suffering the penalty of transferring way more information across the network than you need to (which is slow), but c# isn't able to perform the operations nearly as efficiently as a database. that's partly because it looses access to any indexes, any database caching, any cached compiled queries, it isn't as efficient at dealing with data sets that large to begin with, and any higher level optimizations of the query itself (databases tend to do a lot of that).
next, you have a query inside of your
from f in db.a_lage_table where [...] that is performed for every row in the sequence. if the entire query is evaluated at the database level that would potentially be optimized, and even if it's not you're not going across the network to pass information (which is quite slow) for each record.
from p in db.sometable.tolist()
this basically says "get every record from sometable and put it in a
list", without filtering at all. this is probably your problem.
- LINQ Query takes too long
- Linq query in controller takes too long
- Linq query takes too long when using Func & OrderByDescending
- Linq query takes far too long
- Linq query over mysql table takes too long
- Linq query taking too long
- Linq 'contains' query taking too long
- LINQ query to retrieve pivoted data taking too long
- Linq query taking too long to process results
- LINQ double Join takes too long to execute
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Linq query built in foreach loop always takes parameter value from last iteration
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- linq query Take() takes precedence over Distinct()?
- LINQ Source Code Available
- Linq query runs in a fraction of a second, but .ToList() takes 3.5 seconds
- Is this LINQ Query too long?
- linq - how do you do a query for items in one query source that are not in another one?
- How can I write the following code more elegantly using LINQ query syntax?
- How to dynamic add filters to a LINQ query against an Odata Source in C#
- C# Linq query help removing foreach loops creating cleaner code
- Use a linq query as microsoft local report Data Source (WinForms)
- Determine the source DataContext for a Linq to Sql query
- LINQ query returns old results when source list is re-initialized
- How to get SQL query into LINQ form in C# code
- IEnumerable takes too long to process when filtering on it
- why this simple linq query takes so much time?
- How can I code a Linq query to do an upward Include?
- Convert string to long type and use in a linq query within asp.net MVC
- creating Linq to sqlite dbml from DbLinq source code
More Query from same tag
- Using two different data context in a LINQ JOIN Query
- LINQ query for retrieving items that contain any value from a list?
- What am I doing wrong in this SQL to LINQ conversion?
- C# WPF delete item with its primary key from database using datagrid
- Null check String.ToLower in Linq Where expression
- C#. Inner join to dataGrid, wrapping
- Append IQueryable with additional query parts
- Linq query : Translate local variable reference
- C# LINQ How to efficiently deal with a null return?
- What conditions are required for running loop in parallel in C#?
- LINQ - EF Core - Return object that contains two objects (referenced by property) in nested list
- Saving an xml file using stream results in a duplicate root elements
- LINQ count items created before or the same day past X days
- XElement.Elements() extension method?
- Take all items in sub-categories using LINQ
- How use my own function in Linq query?
- Linq to select most recent file by relative file path
- Complex LINQ query - multiple table relationships
- C# LINQ To Sql Default Object Instantiation Over Optimization?
- LINQ using dictionary in where clause
- Populating a List<class> from a query, results from List is address of the class
- FirstOrDefault Behavior with Int and Int?
- Handling Exchange Web Services (EWS) missing properties
- Use view model property to populate drop down list for
- DataReader to Linq'd query of Dictionary(String, Object)
- Using contains to match two fields
- removing duplicates in a list with linq
- Linq to Sql in ASP.Net MVC 4 returns actual query string
- Linq to XML Queries
- C# linq grouping with same name