小编Aar*_*man的帖子

如何使用SqlAzureExecutionStrategy和"Nolock"

为了处理SQL超时我正在尝试使用SqlAzureExecutionStrategy(https://msdn.microsoft.com/en-us/data/dn456835.aspx)

我遇到的问题是,它可以防止"用户发起的交易",这似乎是实施"与(NOLOCK)",在EF(推荐方式http://www.hanselman.com/blog/GettingLINQToSQLAndLINQToEntitiesToUseNOLOCK.aspx,NOLOCK与Linq to SQL).

示例代码

    public AspnetUser GetAspnetUserByUserName(string userName)
    {
        using (var tx = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = IsolationLevel.ReadUncommitted }))
        {
            return context.AspnetUsers.Where(x => x.UserName == userName).FirstOrDefault();
        }
    }
Run Code Online (Sandbox Code Playgroud)

抛出错误

配置的执行策略"SqlAzureExecutionStrategy"不支持用户启动的事务.有关其他信息,请参阅http://go.microsoft.com/fwlink/?LinkId=309381.

我已经看到了在每次调用的基础上关闭SqlAzureExecutionStrategy的答案,但是如果我的所有读取都忽略了策略,那将无法使用它.可以同时拥有"NoLock"和SqlAzureExecutionStrategy

linq entity-framework azure entity-framework-6 azure-sql-database

8
推荐指数
1
解决办法
4494
查看次数

静态变量如何与 Azure 网站的多个实例一起使用

运行 Azure 网站的多个实例时,静态变量如何工作?这是一个没有完全理解“什么”天蓝色网站的基本问题。取下面的简化代码。

static int MyCachedInt=10;

public ActionResult SetMyCachedInt(int a)
{
    MyCachedInt = a;
    return this.Content(MyCachedInt.ToString());
}

public ActionResult GetMyCachedInt()
{
    return this.Content(MyCachedInt.ToString());
} 
Run Code Online (Sandbox Code Playgroud)

在单个 Web 服务器或传统虚拟机上,我希望每个网站要么返回 10,要么返回最后设置的任何值。使用 Azure 是所有网站都返回相同的值还是每个实例都会单独更新?如果 Azure 扩展一个新网站,该值是 10 还是先前扩展的网站的最后一个实例?

asp.net-mvc azure

5
推荐指数
0
解决办法
1112
查看次数