Reputation: 12711
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?
Upvotes: 0
Views: 83
Reputation: 43067
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.
Upvotes: 6