-1

Having an DbContex:

public class ProductsContext : DbContext
{
  public DbSet<Product> Products;
}  

I can do this:

Product product = _context.Products.Find(1);  

I want to do that in an generic way

IDbSet<T> set = _context.Set<T>();
T entity = set.Find(1);

There are any Entity Framework related performance difference between the two or is the same thing?

ramaral
  • 6,149
  • 4
  • 34
  • 57

1 Answers1

0

You can use query-profiler for performance issue.

MajidTaheri
  • 3,813
  • 6
  • 28
  • 46
  • @ramaral, http://stackoverflow.com/questions/17307326/c-sharp-generic-vs-not-generic-performance – MajidTaheri Feb 22 '14 at 16:01
  • @ramaral Code performance? Are you joking? Your db interaction will take 10000x more time than the dirfferene in code runtime, so it is not even measurable the moment you hit an external server. – TomTom Feb 22 '14 at 16:24
  • @TomTom Yes I know! But my question is if are any significant differece between the two. – ramaral Feb 22 '14 at 16:33
  • @TomTom: Unfortunately EF has a lot of surprises about its pure code performance (mainly probably because heavy reflection is involved). Things like `Attach`ing an object (= just code in memory) can be slower than loading it from the DB. When inserting lots of objects change detection (= internal `DetectChanges` calls) can consume much more time than the actual writing into DB, etc., etc. – Slauma Feb 22 '14 at 16:35