Posts

Showing posts from September, 2019

Entity Framework - Things you should be aware of…

Image
1. Entity Cache First thing to be aware of is entity caching In this example, the first query reads data from the repository and materialize the data to a category entity, and update its Name. Then the repository is queried again by Name. After reading the data, Entity Framework founds the primary key is the same as the cached entity, so Entity Framework does not materialize the data just read, it reuses the previous category entity. Performance is improved by skipping the materialization, but tricky results can happen. When using DbSet .SqlQuery to directly execute SQL query in the repository, Entity Framework still looks up cache before materializing. 2. Materializing a new entity (no caching) Entity is not cached when tracking is turned off, or entity is not queried from the repository. Each of the following queries materializes a new entity: 3. DbSet.Find DbSet.Find accepts the primary keys and returns an entity. Calling Find can improve the performance, because i...