Sitemap
.Net Programming

Explore the .Net with the latest in C# from basic to advanced, including .Net versions 9, 8, 6, 5, Core 3.1, .Net Framework, ASP.NET Core, MVC, design patterns, OOPS, and SOLID principles. Get top tutorials, best practices, and hands-on code examples on GitHub.

Generated using Chat GPT 4

Member-only story

20 Essential Entity Framework Core Tips: Optimize Performance, Streamline Queries, and Enhance Data Handling

6 min readApr 12, 2024

--

1. Use AsNoTracking for Read-Only Scenarios

AsNoTracking fetches data that is not intended to be changed in the current context. It makes queries faster and more efficient because EF Core does not need to capture tracking information.

var users = context.Users.AsNoTracking().ToList();

The aforementioned query retrieves all users from the database without any tracking overhead, which provides performance gain in data-heavy application

2. Opt for Explicit Loading

Explicit loading is a process where related data is loaded from the database at a later time and not immediately with the initial query.

var book = context.Books.Single(b => b.BookId == 1);
context.Entry(book).Collection(b => b.Authors).Load();

--

--

.Net Programming
.Net Programming

Published in .Net Programming

Explore the .Net with the latest in C# from basic to advanced, including .Net versions 9, 8, 6, 5, Core 3.1, .Net Framework, ASP.NET Core, MVC, design patterns, OOPS, and SOLID principles. Get top tutorials, best practices, and hands-on code examples on GitHub.

Sukhpinder Singh | C# .Net
Sukhpinder Singh | C# .Net

Written by Sukhpinder Singh | C# .Net

C# .Net developer 👨‍💻 who's 100% convinced my bugs are funnier than yours. 🐛💥 #BugLife Pubs: https://medium.com/c-sharp-programming

Responses (1)