Click here to Skip to main content
15,887,361 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why is there such a big preformance Issue when using .Where method with DataContext?

Example 1, takes under 1sec to retrieve it's values.

XML
public List<EMPLOYEE> FindEmployees(string prefix)
        {
            var query = (from e in context.EMPLOYEEs
                        where e.EMP_SURNAME.ToUpper().StartsWith(prefix)
                        orderby e.EMP_SURNAME
                        select e).Take(15);

            return query.ToList();
        }


Example 2. Takes up to 10sec

XML
public List<EMPLOYEE> FindEmployees(Func<EMPLOYEE, bool> predicate, int count)
        {
            var query = context.EMPLOYEEs.Where(predicate).Take(count);
            return query.ToList();
        }


And I would call this methods like this.

var employees = FindEmployees(p => p.EMP_SURNAME.ToUpper().StartsWith(prefixText.ToUpper()), 15);


Please any help would be much appreciated.
Posted

Use deferred execution (i.e conversion of linq query to SQL syntax first and then its execution). It is faster, additionally you can compile linq queries to make it faster. Search out for it.
 
Share this answer
 
Take Advantage .Net 4. Great performance improvement, i started loving Linq now :). http://msdn.microsoft.com/en-us/library/dd460688.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900