c# - NoLock in Entity Framework -
i trying read records table when table locked due particular transaction.
i 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 missing implement nolocks. still show timeout. missing ?
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); } }
Comments
Post a Comment