Saeed Esmaeelinejad on LinkedIn: It's important to mention that for EF core queries the… (2024)

Saeed Esmaeelinejad

Senior Software Engineer @ Seven Peaks | .NET Enthusiast & Content Creator

  • Report this post

It's important to mention that for EF core queries the AsNoTrackingWithIdentityResolution has the worst performance!In a very simple way, by using AsNoTracking you tell EF that don't track any entity, right?If Tracking is enabled, a single primary key would create only one single object and will attach it to context.If tracking is NOT enabled, then for every row, a new object would be created. So even though primary key is same, EF core will create multiple objects of the same entity means identity resolution is not used by EF, so we can say No tracking and No identity resolution!By using AsNoTrackingWithIdentityResolution, identity resolution is enabled, but it does not enable tracking of entities. So if there is multiple objects with the same primary key, EF will reuse only one object for them.With above definition it seems the third option should be more optimized and better but surprisingly not! there is an open issue on EF core repo that shows AsNoTrackingWithIdentityResolution has some problem with its implementation and caused bad performance, follow the issue here:https://lnkd.in/gvAhZxnx

54

5 Comments

Like Comment

Rafael Queiroz

Senior Software Engineer | Team Leader | AWS certified

2d

  • Report this comment

Dapper

Like Reply

1Reaction

yadav dhakal

Snr Software Developer C#

3d

  • Report this comment

That's the reason we believein ADO.Net.

Like Reply

1Reaction 2Reactions

See more comments

To view or add a comment, sign in

More Relevant Posts

    • Report this post

    EF Core 9: Reducing database roundtrip!When it comes to query optimization, one of the considerations is reducing database roundtrip as we need to avoid unnecessary database calls, if possible.It is easy to make mistakes when using EntityFramework because you're writing C# code, not SQL thus you may forget how EF will translate this code to SQL and sometimes it will split the code into multiple database queries to gather all the data you need.One of the common examples is using `Count()` method which is used for getting the number of rows for a specific query and needs a separate database query.EF core 9 is trying to solve this issue for us and it is nice to see they care about this small correction for our Linq codes. It can help to have better query performance as instead of calling the database twice we need only one!As a tip, always check EF-generated SQL queries even if you're not an SQL expert still you can know how it executes your queries.What do you think about the new feature?#dotnet #entityframework #queryoptimization

    • Saeed Esmaeelinejad on LinkedIn: It's important to mention that for EF core queries the… (8)

    444

    21 Comments

    Like Comment

    To view or add a comment, sign in

  • Saeed Esmaeelinejad

    Senior Software Engineer @ Seven Peaks | .NET Enthusiast & Content Creator

    • Report this post

    In-Memory Caching in ASP.NET Core In-Memory cache allows storing data within the `application's memory`.We all know using a caching strategy can drastically improve performance and it's quite reasonable as you're getting data from memory not external sources.The flow is straight, trying to get data from the cache if data is presented then return it directly to the caller otherwise call an external DataSource, update the cache, and finally return the data to the caller, no magic!Let's talk about some consideration:- Sticky Sessions: When using in-memory caching in a server farm (multiple servers), ensure that sessions are sticky. Sticky sessions route requests from a client to the same server, maintaining cache consistency.- Memory Resource: Remember that memory is a scarce resource. Limit cache growth to avoid excessive memory usage.- Expiration and Size Control: Use expirations and methods like SetSize to manage cache size. The ASP.NET Core runtime does not automatically limit cache size based on memory pressure; you need to handle this.I have a question, do you use cache on API that returns a list of items with pagination and filters? please explain your idea:)#aspnetcore #dotnet #caching

    • Saeed Esmaeelinejad on LinkedIn: It's important to mention that for EF core queries the… (13)

    315

    6 Comments

    Like Comment

    To view or add a comment, sign in

  • Saeed Esmaeelinejad

    Senior Software Engineer @ Seven Peaks | .NET Enthusiast & Content Creator

    • Report this post

    Do you know what the order of loading configuration is in .NET Host?So usually our program.cs start with `Host.CreateDefaultBuilder()` and we just start using IConfiguration in the rest of it, right?There are different configuration providers that .NET tries to read in order!For example, if you have some configuration in the environment variable it will overwrite your values in the appsettings.json as a matter of loading order.Of course, you can clear providers first and again add only your appsetting from a json file.Read the complete details here: https://lnkd.in/gPkWgSsq

    • Saeed Esmaeelinejad on LinkedIn: It's important to mention that for EF core queries the… (18)

    138

    Like Comment

    To view or add a comment, sign in

  • Saeed Esmaeelinejad

    Senior Software Engineer @ Seven Peaks | .NET Enthusiast & Content Creator

    Good to know how many steps your request will pass until reaches your code!ASP.NET Core is highly customizable and it's possible to change request behavior by using Middleware.When we say changing request road by using Middleware thus the order of them matters, by knowing these possibilities, it's easy to organize your code.Keep in mind, all your API stuff like Actions or Endpoints are in `one` middleware, remember when calling `app.UseControllers()` actually this is a middleware, and guess what? all ActionFilters or EndPointFilters are executing inside that middleware!I always like to know the pipeline not only ASP.NET but also all other frameworks I use.In this image, I excluded the outer parts like DNS resolvers but this is the main gist of the pipeline.Anything you want to add regarding the ASP.NET pipeline?#pipeline #aspnetcore

    • Saeed Esmaeelinejad on LinkedIn: It's important to mention that for EF core queries the… (23)

    222

    8 Comments

    Like Comment

    To view or add a comment, sign in

  • Saeed Esmaeelinejad

    Senior Software Engineer @ Seven Peaks | .NET Enthusiast & Content Creator

    • Report this post

    Is Clean Code dead? Just watched this video from Nick Chapsas was very interesting talk."Don't get too attached to your code, you're not your code!"I agree with that, most of the companies don't follow many of the famous patterns and they don't need either. It is simple to find out: check one of the .NET repo codes!Let me know you're thought about the subject.https://lnkd.in/dt67XTm4

    Why Developers Hate "Clean Code"?

    https://www.youtube.com/

    30

    3 Comments

    Like Comment

    To view or add a comment, sign in

  • Saeed Esmaeelinejad

    Senior Software Engineer @ Seven Peaks | .NET Enthusiast & Content Creator

    • Report this post

    How much do you agree with this claim?Personally, I believe sometimes you need to make your hands dirty and start recreating the wheel with a fresh mindset.

    • Saeed Esmaeelinejad on LinkedIn: It's important to mention that for EF core queries the… (31)

    46

    24 Comments

    Like Comment

    To view or add a comment, sign in

  • Saeed Esmaeelinejad

    Senior Software Engineer @ Seven Peaks | .NET Enthusiast & Content Creator

    • Report this post

    I asked this question a long time back but worth asking again just to recall your knowledge about SQL indexes.You need to consider this index is on string columns (varchar).#sql #indexing #quiz

    • Saeed Esmaeelinejad on LinkedIn: It's important to mention that for EF core queries the… (36)

    84

    31 Comments

    Like Comment

    To view or add a comment, sign in

  • Saeed Esmaeelinejad

    Senior Software Engineer @ Seven Peaks | .NET Enthusiast & Content Creator

    • Report this post

    How do you write a unit test for a class that accepts an IOptions<T> in the ctor?Mocking it? well, no need!There is a built-in class in .NET called `Options` which contains a `Create` method for this purpose!Although inIntegration Testyou may not need it still for unit testing is useful.If you want to read the detailed post, find it here: 👇

    Create IOptions for Unit Testing codesimple.dev

    111

    6 Comments

    Like Comment

    To view or add a comment, sign in

  • Saeed Esmaeelinejad

    Senior Software Engineer @ Seven Peaks | .NET Enthusiast & Content Creator

    • Report this post

    ASP.NET Core Authorization: Role-Based Access Control (RBAC)There are two different ways of authorization in the ASP.NET Core:- Role-Based- Policy-BasedIn this video, I've covered the first one and shown you how to implement Role-based authorization. I used an easy way without using AuthorizationFilter or even custom middleware!Check it out 👇https://lnkd.in/gYbb6mrU

    🔐 ASP.NET Core Authorization: Role-Based Access Control (RBAC)

    https://www.youtube.com/

    219

    11 Comments

    Like Comment

    To view or add a comment, sign in

Saeed Esmaeelinejad on LinkedIn: It&#39;s important to mention that for EF core queries the… (49)

Saeed Esmaeelinejad on LinkedIn: It&#39;s important to mention that for EF core queries the… (50)

  • 334 Posts

View Profile

Follow

Explore topics

  • Sales
  • Marketing
  • Business Administration
  • HR Management
  • Content Management
  • Engineering
  • Soft Skills
  • See All
Saeed Esmaeelinejad on LinkedIn: It&#39;s important to mention that for EF core queries the… (2024)
Top Articles
Latest Posts
Article information

Author: Stevie Stamm

Last Updated:

Views: 5863

Rating: 5 / 5 (80 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Stevie Stamm

Birthday: 1996-06-22

Address: Apt. 419 4200 Sipes Estate, East Delmerview, WY 05617

Phone: +342332224300

Job: Future Advertising Analyst

Hobby: Leather crafting, Puzzles, Leather crafting, scrapbook, Urban exploration, Cabaret, Skateboarding

Introduction: My name is Stevie Stamm, I am a colorful, sparkling, splendid, vast, open, hilarious, tender person who loves writing and wants to share my knowledge and understanding with you.