1

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 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Question: If user 1 update record and same time user 2 update record so which will take action and how this scenario can handle?

Its call "concurrency", To handle this kind so scneario you have to use locking mechanism for handling concurrency (updating same record from different user) so that user may understand that other user is modifying this as well.

Asp.net Entity Framework Aspect:

In asp.net Entity framework has RowVersion property which will track update log for a specific data when it’s been updated.

Two kind of Concurrency Mechanism you can use:

You can have a look official document for more details. Additionally here is the implementations

Database Aspect:

From database you can also handle this scenario. All the database also has Locking mechanism to work on same records simultaneously by multipole user. You can have a look here

Hope it will guide you accordingly and redeem your confusion.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.