score:14
well to start with, i'd find out what query is being generated (in linq to sql you'd set the log on the data context) and then profile it in sql server management studio. play with it there until you've found something that is fast enough (either by changing the query or adding indexes) and if you've had to change the query, work out how to represent that in linq.
i suspect the problem is that you're combining orderby
and take
- which means it potentially needs to find out all the results in order to work out which the top 100 would look like. is code
indexed? if not, try indexing that - it may help by allowing the server to consider records in the order in which they'd be returned, so it can stop after it's found 100 records. you should look at indexes for the other columns too.
score:3
the take(100)
translates to "select top 100" etc. this would help if your problem was an otherwise huge result set, where there are a lot of columns returned. i bet though that your problem is a table scan resulting from the query. in this case, .take(100)
might not help much at all.
so, the likely culprit is the same as if you were doing sql using ado.net: how are your indxes? are the fields being searched fields for which you don't have good indexes? this would cause a drastic decrease in performance compared to queries that do utilize good indexes. add an index that includes code
and name
and see what happens. not using an index for code
is guaranteed to hose you, because of the order by
. also, what field links genealogy_accounts and genealogy_accountclass? a lack of index on either table could hose things. (i would guess an index including searchable is unlikely to help.)
use sql profiler to see the actual query being run (though you can do this in vs too), and to see how bad it really is on the server.
the problem might be linq doing something stupid generating the query, but this is probably not the case. we're finding linq-to-sql often makes better queries than we do. even if it looks goofy, it's usually very efficient. you can put the sql in query analyzer, and check out the query plan. then rewrite the sql to be more human-simple and see if it improve things -- i bet it won't. i think you'll still see a table scan, indicating something is wrong with your index.
Source: stackoverflow.com
Related Query
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Does this LINQ code perform multiple lookups on the original data?
- Shorten this LINQ query via the help of an anonymous type?
- LINQ Source Code Available
- How does this linq code that splits a sequence work?
- multiple orderby in this linq code
- How can I combine this code into one or two LINQ queries?
- How can I further simplify this piece of LINQ code
- Is there a bug in this code from 101 LINQ Samples on MSDN? (Update: Fixed)
- C# Linq query help removing foreach loops creating cleaner code
- How to render this map-reduce javascript code to an equivalent LINQ Select-Aggregate?
- LINQ approach to this code
- Linq expression. Help mimize code
- creating Linq to sqlite dbml from DbLinq source code
- How do i convert this linq code to inline sql
- I need help speeding up this EF LINQ query
- Need help turning this LINQ expression into LINQ statement
- why does this linq code get exponentially slower when applying First() to projection?
- How to convert this recursive code to Linq
- Using Linq to build a graph class; can you make this code look better?
- How to write this code using the Linq Extension Method-Syntax?
- Convert this LINQ code back to a Loop (or Why is this object sometimes null)
- How can I refactor this code for LINQ filtering?
- Why this Linq code always throws System.StackOverflowException?
- Need help rewriting this Linq query to move it from code-behind to DAL as reusable object
- My code is very inefficient for this simple Linq usage
- How I change this code to be in linq style
- Why the extension method of where for LINQ in this code would print out a single number while it shouldn't print anything at all?
- Can someone help me improve this linq
- Linq - how to convert this code to linq
More Query from same tag
- Get top 3 most occuring numbers in a List
- returning single result using LINQ
- Cannot get the dynamic OrderBy to work on my generic list
- Linq to SQL Multiple Table Select as Keyvalue Pair
- Is this the best way to create a frequency table using LINQ?
- INCLUDE in Linq but to include only some columns from the included object
- Linq query to filter id inside a list of list c#
- C# List Sort by Time in Reverse Chronological Order
- OrderBy date format with null values
- Return parent entities based on (and including) child entities
- How to get duplicate items from a list using LINQ?
- Linq query from multiple sets of nested collections
- Simple Sql statement in Linq?
- LINQ: How to join on only a single row with the MAX ID of the join column, and not all rows?
- LINQ to DataTable query
- How can ı remove from duplicated items in C#?
- XDocument Descendants of Descendants
- Hierarchy Employee/Manager from a List
- How to use Linq query Result in OrderBy?
- Modify original value type IEnumerable from .ToArray() reference
- No property or field 'OrderID' exists in type 'XElement' (at index 0)
- LINQ question with string split and arrays in csv files
- retrieving data by LINQ c#
- the type arguments for method system linq enumerable as enumerable - Error
- DataGridView is not updating with database,only works inside the function with parameter(object,EventArgs)
- Get a list of date Ranges from a list Of dates
- Linq to sql add/dynamic OR WHERE clause
- C# Linq exact part of collection
- How to join two entities
- Using Linq to get value from a model asp.net mvc