Performance issues with Lambda expressions: "Old" ODP.NET Entity Framework
vs. "New" MS Entity Framework
If I use the designer to generate my .edmx model with an ODP.NET provider
the entities are generated with types like "ObjectSet". The "new" Entity
Framework by MS uses "DbSet". So there seem to be many changes under the
hood.
The following query works fine with the generated code by the designer
and/or ODP.NET:
var x = from c in db.Customers where c.Id == 82904 select c;
That query has been written by a colleague. Now I'm a bug fan of Lambda
Expressions and wanted to refactor it:
var x = db.Customers.Where(c => c.Id == 82904);
This takes 5s whereas the other query finishes nearly instantly. And a
ToList() gives a timeout exception. It does a full table scan. WHY???
I reproduced it with the EF NuGet package and code first. Inherited from
DbContext, DbSet property and "injected" an OracleConnection in the
constructor.
Both queries take the same time.
What's the problem there? In the generated code I get an IQueryable and
have to to AsEnumerable() to execute the Lambda Expression.
I think it's a bit related to the following issue: Timeout expired when
using a Func<> instead of a lambda
Any ideas?
No comments:
Post a Comment