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
โ Cons of Global Exception
1. It can become harder for handler because sometime it will catch the exception at broad level and deal with it accordingly without digging down to exact lower exception
2. Performance overhead for API to deal all exceptions at one point
๐ก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
๐๐ญ๐๐ฉ ๐ : 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
1๏ธโฃ Plain Text Password
Saving password in plain text is the worst approach because it is open to everyone who has database access and an easy target for attackers. Its not recommended at all.
2๏ธโฃ Hashed Password
Hashing the plain text password first and then saving it, it seems safe but it isnโt safe again, you can fall for attack in this case as well rainbow attack.
โ๏ธIf you like my tweets, please join 400+ Software Engineers to receive an actionable tip weekly in your inbox through my Newsletter.(lnkd.in/d69Va5CM)
โ Use an overload of theย String.Equalsย method to test whether two strings are equal
โ Use theย String.Compareย andย String.CompareToย methods to sort strings, not to check for equality.
โ Use overloads that explicitly specify the string comparison rules for string operations. Typically, this involves calling a method overload that has a parameter of typeย StringComparison.