Muhammad Waseem Profile picture
Mar 21 โ€ข 7 tweets โ€ข 3 min read
๐Ÿ’ก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
๐ˆ๐๐ž๐ง๐ญ๐ข๐ญ๐ฒ ๐‘๐ž๐ฌ๐จ๐ฅ๐ฎ๐ญ๐ข๐จ๐ง : When you use a tracking query in Entity Framework Core, it uses identity resolution to return the same entity instance from the change tracker if it's already being tracked.
#dotnet
However, a no-tracking query doesn't use the change tracker and always returns a new instance of the entity, even if the same entity is contained in the result multiple times

#dotnet
To combine both behaviors, EF Core has added AsNoTrackingWithIdentityResolution(), which uses a stand-alone change tracker to do identity resolution without tracking the results in the context.

Once the query is enumerated, the change tracker is garbage collected

#dotnet
โœ‰ Join my weekly .NET Newsletter with 700+ Software Engineers here : lnkd.in/dcvY9jEE

#dotnet

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Muhammad Waseem

Muhammad Waseem Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @mwaseemzakir

Mar 22
๐Ÿ’กIEnumerable vs IQueryAble in .NET

1) Whatis IEnumerable
2) What is IQueryAble
3) Difference b/w them โฌ

#csharp #dotnet Image
IEnumerable and IQueryable interfaces are both used to work with collections of data and both support LINQ (Language Integrated Query)
#dotnet
๐ˆ๐๐ฎ๐ž๐ซ๐ฒ๐š๐›๐ฅ๐ž

โœ… IQueryable executes queries on the server side.

โœ… It is designed specifically to work with LINQ

โœ… It extends IEnumerable, which means it includes all of the functionality of IEnumerable.
#dotnet
Read 7 tweets
Mar 20
๐Ÿ’กGlobal Error Handling in .NET ?
1) Why we need it
2) Pros and cons
3) Code implementation๐Ÿงต๐Ÿ”ฝ

#dotnet Image
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
Read 5 tweets
Mar 13
๐Ÿ’ก Life of Query in EF

๐’๐ญ๐ž๐ฉ ๐Ÿ : 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.
Read 5 tweets
Mar 12
๐Ÿ’ก 7 Tips to write better LINQ Queries

๐”๐ฌ๐ž ๐จ๐Ÿ ๐€๐ฌ๐๐จ๐“๐ซ๐š๐œ๐ค๐ข๐ง๐  : 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
Read 8 tweets
Mar 11
๐Ÿ’ก How to store Password in Database

Three common practices that are used for passwords, but first two has some serious issues.

โœ”๏ธ Plain text password
โœ”๏ธ Hashed password
โœ”๏ธ Hashed password with Salt
โœ”๏ธWhat is Salt
โœ”๏ธHow to validated hash password

#dotnet

#csharp #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.
Read 7 tweets
Feb 27
๐Ÿ’ก Do and Don't for string in C#

1. Always use
2. Don't use ๐Ÿ”

โœ‰๏ธ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)

#csharpย #dotnetย #dotnetcore
โœ…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.
Read 8 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(