Question

I am trying to read the records from table even when the table is locked due to particular transaction.

I am using below code

public async Task<KeyValuePair<String, List<Om_Category>>> CategoryList(Om_Category obj)
{
    try
    {
        using (var transaction = new TransactionScope(
                TransactionScopeOption.Required,
                new TransactionOptions 
                { 
                    IsolationLevel = IsolationLevel.ReadUncommitted 
                },
                TransactionScopeAsyncFlowOption.Enabled))
        {
            using (var categoryContext = new ModelGeneration())
            {

                categoryContext.Configuration.ProxyCreationEnabled = false;
                var data = await categoryContext
                    .tblCategory
                    .ToListAsync();

                transaction.Complete();

                return new KeyValuePair<String, List<Om_Category>>("", data);
            }
        }
    }
    catch (Exception ex)
    {
        return new KeyValuePair<String, List<Om_Category>>(ex.Message, null);
    }
}

But seems like I am missing something to implement NoLocks. Still it show timeout. Am I missing something ?

1
4
9/30/2015 9:44:45 AM

Accepted Answer

Surprisingly Entity Framework inbuilt Transaction Class worked !!

public async Task<KeyValuePair<String, List<BE_Category>>> CategoryList(BE_Category obj)
{
    try
    {
        using (var categoryContext = new ModelGeneration())
        {
            using (var dbContextTransaction = categoryContext
                      .Database
                      .BeginTransaction(System.Data.IsolationLevel.ReadUncommitted))
            {
                categoryContext.Configuration.ProxyCreationEnabled = false;

                //Code

                dbContextTransaction.Commit();

                return new KeyValuePair<String, List<BE_Category>>("", data);
            }
        }
    }
    catch (Exception ex)
    {
        return new KeyValuePair<String, List<BE_Category>>(ex.Message, null);
    }
}

Reference

2
9/30/2015 12:19:07 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow