.net通過MrAdvice實(shí)現(xiàn)AOP
免費(fèi)的AOP
nuget安裝MrAdvice;
using ArxOne.MrAdvice.Advice; using System; using System.Data.Entity; namespace NBSharp.Core { /// <summary> /// ef實(shí)現(xiàn)with nolock(備用,已用攔截器實(shí)現(xiàn)) /// 使用:在方法上加上[ReadUncommitedTransactionScope]即可 /// </summary> [Serializable] public class ReadUncommitedTransactionScopeAttribute : Attribute//, IMethodAdvice { public void Advise(MethodAdviceContext context) {DbContext db = (DbContext)NBSharpResolver.Resolve<IUnitOfWork>(); //第二種實(shí)現(xiàn) db.Database.ExecuteSqlCommand("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");//with(nolock) context.Proceed();//執(zhí)行aop標(biāo)記的方法
//第二種實(shí)現(xiàn) //https://stackoverflow.com/questions/24684914/get-entity-framework-6-use-nolock-in-its-underneath-select-statements/24699606 //db.Database.ExecuteSqlCommand("SET TRANSACTION ISOLATION LEVEL READ COMMITTED;");//with(lock) } } }
http://www.rzrgm.cn/slyzly/articles/11388441.html

浙公網(wǎng)安備 33010602011771號(hào)