Reputation: 5992
For retrieving data with some criteria from the database, I use this code:
IEnumerable<Object> iEnumuDeclarations2 = ObjectDAO.Find(d => d.id == 1).ToList();
but it is too slow. And at the end an exception out of memory occurs
public IEnumerable<TEntity> Find(Func<TEntity, bool> predicate)
{
return DataContext.CreateObjectSet<TEntity>().Where<TEntity>(predicate);
}
Upvotes: 0
Views: 84
Reputation: 7440
You should use Expression<Func<TEntity, bool>>
instead of Func<TEntity, bool>
The difference is, the expression can be interpreted by EF to generate an SQL query, and execute it on the mssql server, what you are doing essentialy is getting every single object into memory and then query the local objects, depending on the size of your database it could result in out of memory exception but still unlikely. But atleast this explains the slowness.
Upvotes: 1
Reputation: 668
please try this may be it is working :
var iEnumuDeclarations2 = declaration_importationDAO.Where(d => d.id_service == id_service).ToList();
Upvotes: 1