Today in interview I got asked this kind of question.
Let’s say you want to update multiple records same time using web api then how you can do that.
As it is around 1000s of records for updating..
So I give reply to use async and await for now.
Then he ask me if user 1 update record and same time user 2 update record so which will take action and how this scenario can handle.
So what should be best reply for this kind of question.
2
Answers
Question:
If user 1 update record and same time user 2 update record so which will take action and how this scenario can handle?
Asp.net Entity Framework Aspect:
In
asp.net Entity framework
hasRowVersion
property which will track update log for a specific datawhen it’s been updated.
Two kind of Concurrency Mechanism you can use:
Optimistic Concurrency
Pessimistic concurrency
You can have a look
official document
for more details. Additionally here is the implementations
Database Aspect:
Hope it will guide you accordingly and redeem your confusion.
Entity framework is not designed for mass updates – it is designed for queries and transactional updates (a few records at a time).
If you need to mass-update data then either write a SQL statement that will do all of the updates or use an ETL tool like SSIS. So, raw SQL is faster than Entity framework. With that said, For normal CRUD that is not querying a billion rows, EF is totally fine, but when handling a significant amount of data, replacing EF calls with stored procedures is a good choice.