Null Conditional Operator (?.) is used to check if an object/property is null or not. If not, null original value is returned otherwise null is returned
Null Coalescing Operator (??)returns the value of its left-hand operand if it isn't null; otherwise, it evaluates the right-hand operand and returns its result.
Null Coalescing Assignment Operator ??= assigns the value of its right-hand operand to its left-hand operand only if the left-hand operand evaluates to null. The ??= operator doesn't evaluate its right-hand operand if the left-hand operand evaluates to non-null
HttpClient is a class in C# that is used for making HTTP calls of different kinds (most commonly Get/Put/Delete/Post).This class comes from namespace System.Net.Http
Most commonly used methods of this class are
- GetAsync
- DeleteAsync
- PostAsync
- PutAsync
- Dispose
๐กTracking vs Non Tracking Queries in .NET 1) Tracking Queries 2) Non Tracking Queries 3) Identity Resolution 4) How to set tracking by default for context๐งต๐ฝ #dotnet
๐๐ซ๐๐๐ค๐ข๐ง๐ : By default all queries are tracked , so behind the seen a change tracker keeps working on each entity. If you want to perform Update/Delete then you should use tracking. #dotnet
๐๐จ๐ง ๐๐ซ๐๐๐ค๐ข๐ง๐ : If you just need read only data then you don't need your queries to keep tracking of change , you can simply go with no tracking and help the query run more speedy. #dotnet
While working with .NET application we sometime come up with exception and we can deal with it in two ways , either by using try catch block in each class (controller level or service level) or we can define a centralized and global point to catch the exception. #dotnet
โ Pros of using Global Exception
1. It provides us a centralized error handling point and makes easier for us to manage.
2. Code readability is improved as we get rid of writing try-catch code in each method #dotnet
๐๐ญ๐๐ฉ ๐ : The LINQ Query is processed by EF Core and build an representation that is processed by database provider, and the result is cached later on so we don't need to process it every time #dotnet
See thread ๐งตโฌ
๐๐ญ๐๐ฉ ๐ : The result is passed to the db provider and db provider identifies which parts of query can be evaluated in db, these parts are then translated into query language (e.g. SQL) after that translated query is sent to db and db returns results (but not entity instances)
๐๐ญ๐๐ฉ ๐ : For each item we check if it is tracking query EF checks the data in existing change tracker if found relevant entity is returned else new is created, its change tracking get set up and it is returned
For non tracking a new entity is always created and returned.
๐๐ฌ๐ ๐จ๐ ๐๐ฌ๐๐จ๐๐ซ๐๐๐ค๐ข๐ง๐ : For read only queries e.g. (GetAll,GetById etc.) use AsNoTracking , when we use it entities are not tracked for change so it brings data more speedily. #dotnet
See thread ๐งต๐ฝ
๐๐ง๐๐ฅ๐ฎ๐๐ ๐ง๐๐๐๐ฌ๐ฌ๐๐ซ๐ฒ ๐๐ง๐ญ๐ข๐ญ๐ข๐๐ฌ ๐๐ง๐ ๐๐จ๐ฅ๐ฎ๐ฆ๐ง๐ฌ : While retrieving data from multiple table make sure to include only necessary tables and columns Use eager loading only when it is necessary. #dotnet
๐ ๐จ๐ซ ๐ฅ๐๐ซ๐ ๐ ๐๐๐ญ๐ ๐ฎ๐ฌ๐ ๐๐ค๐ข๐ฉ ๐๐ง๐ ๐๐๐ค๐ : Use skip and take to retrieve data from table for large collections because if we try to bring all data in single try it can take time that will give bad user experience takes next values. #dotnet