I have a Table named ProjectActivity with Primary Key: ProjectCode and ActivityId and Index on ProjectCode Our websites generate query on this table (without involving other tables) and always requesting rows with same ProjectCode
Sometimes we start a job in c# that deletes every rows with a specific ProjectCode and inserts new rows for that specific ProjectCode in a transaction.
using (var dbContextTransaction = db.Database.BeginTransaction())
{
try
{
db.Database.ExecuteSqlCommand("delete FROM [TS_Repository].[dbo].[ProjectActivities] where ProjectCode = {0} ", project.Code);
LogManager.WriteRequestLog("Deleted Existing Project Activities");
if (ProjectActivities.Count > 0)
{
db.Set<ProjectActivity>().AddRange(ProjectActivities);
db.SaveChanges();
}
dbContextTransaction.Commit();
LogManager.WriteRequestLog("Refresh ProjectActivities succesfully for " + project.Title);
}
catch (Exception exc)
{
dbContextTransaction.Rollback();
throw exc;
}
}
Our issue is that, while this transaction (3/4 minutes) processing, our websites can't perform any query (whole table is locked). We should obtain this scenario: Until transaction being committed, website should query "old" data. Is this scenario possible to implement? I can figure it out that we have to trick with lock and isolation level.
Thank you in advance for any tips.