Suppose I have code which retrieves an object and modifies it and submits it via any ORM from a web application. Below is the pseudo code:First requestvar objCust = _dbContext.Customers.Where(c=>c.CustomerId == ALFKI).SingleOrDefault();objCust.Address =test address 1;//and add some orders_dbContext.SubmitChanges(); Second simultaneous requestvar objCategory = _dbContext.Categories.Where(c=>c.CategoryId == 1).SingleOrDefault();objCategoryName = test name;_dbContext.SubmitChanges();How does the first request only grasp the changes done to customers and submit the changes. Is there any mechanism inbuilt in ORM's to track changes to entities per thread or request.
How do ORM'S manage CRUD operations in multi thread environment
c#;asp.net;orm
Most O/RMs are not thread-safe. When using an O/RM in a web app, the common practice is to create a UnitOfWork per request that is tied to that request's thread. Another option is to expose the UnitOfWork as a [ThreadStatic] variable. And finally, there are some Dependency Injection containers that will allow you to tie the lifetime of an object (e.g. a UnitOfWork) to a thread.