使用NOLOCK的实体框架查询

时间:2018-06-29 03:33:35

标签: entity-framework

这个问题被问了很多。 我发现这个Entity Framework with NOLOCK

测试时,我注意到带有join的查询

  

将事务隔离级别设置为已读

该解决方案似乎仅适用于单表查询, 如何标记多表联接查询

  

设置事务隔离级别未提交

以下是我的测试代码:

class Program
    {
        static void Main(string[] args)
        {
            TransactionOptions transactionOptions = new TransactionOptions();
            transactionOptions.IsolationLevel = IsolationLevel.ReadUncommitted;

            using (var scope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
            {

                using (var context = new BloggingContext())
                {                    
                    (from a in context.Set<Post>()
                     join b in context.Set<Blog>() on a.BlogId equals b.BlogId
                     select new { a, b }).FirstOrDefault();

                    context.Set<Blog>().FirstOrDefault();
                    context.Set<Blog>().ToArray();

                    scope.Complete();
                }
            }          

0 个答案:

没有答案