Hassan Vaezzadeh
Software Engineer | .NET Developer
- Report this post
๐ข 5 Techniques to Optimized EF Query in .NET Core1๏ธโฃ Get fields you need onlyIt is about optimizing data retrieval by selecting only the specific fields required for a particular operation, rather than fetching entire entity objects.2๏ธโฃ Avoid N+1 QueriesIt occurs when your application makes one query to retrieve a set of objects, and then additional queries for each object to retrieve related data. This can lead to a significant performance bottleneck, especially when dealing with a large number of objects.3๏ธโฃ Using .AsNoTracking()Using AsNoTracking in Entity Framework Core is a performance optimization technique particularly useful in scenarios where you are only reading data from the database and do not intend to update or delete it.4๏ธโฃ Avoiding Cartesian ExplosionA cartesian explosion refers to a situation where a query unintentionally produces a disproportionately large number of records due to the way joins are handled, significantly impacting the performance and efficiency of the query.5๏ธโฃ Use AsSplitQuery()the AsSplitQuery() method is used to split queries that retrieve multiple related entities into separate SQL queries. This can sometimes improve performance, especially when dealing with complex queries or large datasets.#dotnetcore #efcore #ef #csharp #dotnetdeveloper
144
3 Comments
Mohammad Goroohi
.NET Developer | Maui Android Developer | Blazor
5mo
- Report this comment
excellent! These EF Query optimization techniques are really useful in .NET Core. Especially the use of AsNoTracking and AsSplitQuery, which can have a significant effect on improving performance. Thanks for sharing these valuable tips!
1Reaction 2Reactions
Pavel Vasilevich
.Net Backend Developer
5mo
- Report this comment
Very useful tips
1Reaction 2Reactions
ehsan soltani
.Net/Flutter developer
5mo
- Report this comment
Thank you for sharing
1Reaction 2Reactions
To view or add a comment, sign in
More Relevant Posts
-
Dipak Pakhale
๐ฑFounder at Sparkle Web | IT Services & Consultancy Expert | Empowered 30+ Entrepreneurs & Founders to Transform Digitally | Website & Mobile App Development | Boosting Client Business with 5X Growth๐
- Report this post
Understanding the ๐๐ข๐๐๐๐ซ๐๐ง๐๐ ๐๐๐ญ๐ฐ๐๐๐ง ๐๐๐ ๐๐ซ ๐ฅ๐จ๐๐๐ข๐ง๐ ๐๐ง๐ ๐ฅ๐๐ณ๐ฒ ๐ฅ๐จ๐๐๐ข๐ง๐ ๐ข๐ง ๐๐ง๐ญ๐ข๐ญ๐ฒ ๐ ๐ซ๐๐ฆ๐๐ฐ๐จ๐ซ๐ค can significantly impact your application's performance and resource usage.With ๐๐๐ ๐๐ซ ๐ฅ๐จ๐๐๐ข๐ง๐ , all related entities, such as products and their associated categories, are fetched upfront in a single database query. This reduces the need for additional queries when accessing related data.In contrast, ๐ฅ๐๐ณ๐ฒ ๐ฅ๐จ๐๐๐ข๐ง๐ delays the loading of related entities until they're explicitly accessed. While convenient, this approach can result in additional queries being executed on-demand, potentially impacting performance.Understanding when to use each loading strategy is crucial for optimizing data retrieval in Entity Framework applications.#entityframework #performanceoptimization #dataretrieval #csharp #dotnet #orm
32
Like CommentTo view or add a comment, sign in
-
sudip ranabhat
Senior .NET Developer | Software Architecture Enthusiast | .Net Core, C# ,Web API | Agile Methodologies | Research and Development
- Report this post
Implementing Global Query Filter in EntityFramework is a good practice, especially for soft delete.But if you are using Database First Approach, every time you do a reverse engineering , this query filter will reset.How can it be done using Database First Appraoch? Click the link below โฌ https://lnkd.in/gnPxdHk3โฉ Reshare with your network if this is helpful#003 #dotnet #softwareengineering #softwaredevelopment
9
Like CommentTo view or add a comment, sign in
-
Elliot One
Senior Full Stack Engineer | Founder at XANT
- Report this post
Let's review Predicate and Expression in C#!Predicate<T> and Expression<Func<T, bool>> in C# are two powerful tools for data filtering.Predicate<T>:+ Is a delegate to define criteria that return a boolean to indicate whether an object meets these conditions.+ It's ideal for in-memory filtering of collections, providing a straightforward way to filter data without complex setups.Expression<Func<T, bool>>:+ Shines when working with Entity Framework Core.+ This tool allows you to build expression trees that are translated into SQL queries.+ Helps to dynamically construct complex queries that EF Core can efficiently translate into database queriesWhy Use Expressions?1. Expressions let you construct queries on-the-fly based on runtime conditions.2. By translating expression trees into SQL, you leverage the database's processing power for filtering, making it more efficient than loading all data into memory.3. Expressions enable you to write modular and reusable query logic. 4. With Expressions, you seamlessly integrate with LINQ and EF Core, making it easier to write clean and maintainable code.5. Building intricate queries with ease.Predicate<T> and Expression<Func<T, bool>> together offer a robust approach to data filtering, whether you're working with in-memory collections or querying a database.โ They help build more powerful, dynamic, modular, and scalable queries.โ Share your experiences using Expressions in the comments!-- Follow Elliot One for more software engineer posts.#dotnet #efcore #softwareengineering
329
35 Comments
Like CommentTo view or add a comment, sign in
-
Dipak Pakhale
๐ฑFounder at Sparkle Web | IT Services & Consultancy Expert | Empowered 30+ Entrepreneurs & Founders to Transform Digitally | Website & Mobile App Development | Boosting Client Business with 5X Growth๐
- Report this post
Are you curious about the differences between Database-First and Code-First approaches in Entity Framework? Let's understand it!๐๐๐ญ๐๐๐๐ฌ๐-๐ ๐ข๐ซ๐ฌ๐ญ:Start with an existing database and generate models from it. Perfect for when your database is already set up.๐๐จ๐๐-๐ ๐ข๐ซ๐ฌ๐ญ:Start with the code, then create the database. Ideal for when you want full control over your models and database design.๐๐ก๐ข๐๐ก ๐ญ๐จ ๐๐ก๐จ๐จ๐ฌ๐?โบ Database-First: Use this if your database is already built.โบ Code-First: Choose this if you want to design your database through code.Understanding these approaches helps you pick the right one for your project. Happy coding!Stay tuned for more easy tech tips! Like, Repost, and Comment below!#dotnet #entityframework #databasefirst #codefirst #csharp
130
1 Comment
Like CommentTo view or add a comment, sign in
-
Junaid Khan
Full Stack .Net Developer | Asp .Net Core | C# | Blazor | Web API | SQL Server | Entity Framework Core |
- Report this post
Code First vs Database First
1
Like CommentTo view or add a comment, sign in
-
-
Shwetha M D
Software Developer (.net ), immediate joiner. | ASP.net MVC | c# | ASP.net core Web API | Entity Framework | Linq |SQL |Typescript |Angular
- Report this post
LINQ (Language Integrated Query) in C# is a feature that lets you query and manipulate data directly within your codeusing a SQL-like syntax or method calls. It supportsquerying various data sources such as collections, databases,XML, etc., with powerful operators like Where, Select, OrderBy, and more.LINQ provides efficient querying through deferred execution and integrates seamlessly withC# for improved code readability and maintenance.Example:// Sample dataList<int> numbers = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };// Query Syntaxvar evenNumbersQuery = from num in numberswhere num % 2 == 0select num;// Method Syntaxvar evenNumbersMethod = numbers.Where(num => num % 2 == 0);// Iterating through resultsforeach (var num in evenNumbersQuery){Console.WriteLine(num); // Output: 2, 4, 6, 8, 10}foreach (var num in evenNumbersMethod){Console.WriteLine(num); // Output: 2, 4, 6, 8, 10}
2
Like CommentTo view or add a comment, sign in
-
Ahmed Yezdane
Full-Stack Developer | ASP.NET Core | Vue.js | Back end Developer Dotnet | .Net Enthusiastic | Software Engineer .Net
- Report this post
๐๐ฃ๐๐๐ง๐จ๐ฉ๐๐ฃ๐๐๐ฃ๐ ๐ฌ๐๐๐ฉ ๐๐๐ ๐ฆ๐ช๐๐ง๐๐๐จ ๐ฎ๐ค๐ช๐ง ๐๐๐๐ ๐๐ค๐๐ ๐๐๐ฃ๐๐ง๐๐ฉ๐๐จ ๐๐๐ฃ ๐๐ ๐ฉ๐ง๐๐๐ ๐ฎNormally, the SQL commands executed by Entity Framework (EF) can appear ๐ช๐ฎ๐ข๐ญ๐ ๐๐ข๐๐๐๐ซ๐๐ง๐ญ ๐๐ซ๐จ๐ฆ ๐ญ๐ก๐ ๐๐๐๐ queries that created them. This mismatch can make it difficult to analyze and debug your code.โญ EF's query tags feature comes to the rescue!This feature lets you add a short, descriptive comment directly into the generated SQL query.This comment acts as a bridge, making it easier to ๐บ๐ฎ๐๐ฐ๐ต ๐๐ต๐ฒ ๐ฆ๐ค๐ ๐ฏ๐ฎ๐ฐ๐ธ ๐๐ผ ๐๐ต๐ฒ ๐ผ๐ฟ๐ถ๐ด๐ถ๐ป๐ฎ๐น ๐๐๐ก๐ค ๐ฐ๐ผ๐ฑ๐ฒp.s: check out the post about TagWithCallSite's twin:https://lnkd.in/dfXP869W#dotnet #efcore #csharp
40
2 Comments
Like CommentTo view or add a comment, sign in
-
Marya Amouri
Backend Developer | ASP.NET Core
- Report this post
#DbContext in Entity Framework Core๐ท๏ธ DbContext is a component for managing entities, relationships and configuring #EFCore 's behavior.๐ท๏ธ DbContext is a #DotNet class, that acts intermediate between the .NET application and the database๐ท๏ธDbContext plays a crucial role in managing entities, tracking changes, and coordinating database operations.๐ท๏ธKey Responsibilities of DbContext:๐๏ธ Tracks the state of entities (Added, Deleted, Modified, UnChanged),to generate appropriate SQL statements when saving changes to the database.๐๏ธ Database Interaction: DbContext provides methods to interact with the database including:โ Querying entities.โ Saving changes.โ Executing raw SQL commands.โ Managing transactions.๐๏ธ DbContext translates #LINQ queries written in your application into SQL queries that can be executed against the database. This translation is handled by EF Core's query pipeline.๐๏ธ Configuration and Relationships:DbContext allows you to configure various aspects of EF Core, including :โ Connection settingsโ Entity mappingsโEstablish relationships (e.g., one-to-many, many-to-many) between entities.โ Database initialization strategies.#EntityFrameworkCore #DbContext #ORM #DotNetDevelopment #SoftwareEngineering #backend
16
Like CommentTo view or add a comment, sign in
-
Ahmed Yezdane
Full-Stack Developer | ASP.NET Core | Vue.js | Back end Developer Dotnet | .Net Enthusiastic | Software Engineer .Net
- Report this post
๐๐ฃ๐๐๐ง๐จ๐ฉ๐๐ฃ๐๐๐ฃ๐ ๐ฌ๐๐๐ฉ ๐๐๐ ๐ฆ๐ช๐๐ง๐๐๐จ ๐ฎ๐ค๐ช๐ง ๐๐๐๐ ๐๐ค๐๐ ๐๐๐ฃ๐๐ง๐๐ฉ๐๐จ ๐๐๐ฃ ๐๐ ๐ฉ๐ง๐๐๐ ๐ฎNormally, the SQL commands executed by Entity Framework (EF) can appear ๐ช๐ฎ๐ข๐ญ๐ ๐๐ข๐๐๐๐ซ๐๐ง๐ญ ๐๐ซ๐จ๐ฆ ๐ญ๐ก๐ ๐๐๐๐ queries that created them. This mismatch can make it difficult to analyze and debug your code.โญ EF's query tags feature comes to the rescue!This feature lets you add a short, descriptive comment directly into the generated SQL query.This comment acts as a bridge, making it easier to ๐บ๐ฎ๐๐ฐ๐ต ๐๐ต๐ฒ ๐ฆ๐ค๐ ๐ฏ๐ฎ๐ฐ๐ธ ๐๐ผ ๐๐ต๐ฒ ๐ผ๐ฟ๐ถ๐ด๐ถ๐ป๐ฎ๐น ๐๐๐ก๐ค ๐ฐ๐ผ๐ฑ๐ฒ#dotnet #efcore #csharp
78
8 Comments
Like CommentTo view or add a comment, sign in
3,955 followers
- 74 Posts
View Profile
FollowExplore topics
- Sales
- Marketing
- IT Services
- Business Administration
- HR Management
- Engineering
- Soft Skills
- See All