fatiDev
fatiDev

Reputation: 5992

Exception "Out of Memory" in EF

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

Answers (2)

Rand Random
Rand Random

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

Kaval Patel
Kaval Patel

Reputation: 668

please try this may be it is working :

var iEnumuDeclarations2  = declaration_importationDAO.Where(d => d.id_service == id_service).ToList();

Upvotes: 1

Related Questions