0

I'm using Entity framework in my ASP.NET MVC project. I need to know that if I'm dealing correctly with the following scenario.

Lets say my Employee table has over 100000 records and I have to apply various filtering according to the client requirement.

So I write 1 method ReadAll() to retrieve all the records from the database and then apply filtering to the datasource using lambda expressions.

Ex: Get employee by ID

public List<Employee> ReadAll()
{
   // return List<Employee>
} 


private Employee(int id)
{
   Employee obj=ReadAll().where(o=>o.empID == id).First();
}

I'm trying to use one read all method because there are various filtering to be applied and I do not have to write separate database access methods to each of them.

Will this affect my application performance adversely?

1
  • Ofcourse yes, you should use IQueryable instead of List Commented Oct 7, 2014 at 13:19

1 Answer 1

6

Change ReadAll to return IQueryable so that it won't execute the query until after you've applied your filter and called First() or ToList().

public IQueryable<Employee> ReadAll()
{
   // return List<Employee>
} 

Entity Framework uses a concept called deferred execution. I encourage you to read up on it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.