VS2017和实体框架Core 2.0中的自定义执行策略错误 [英] Custom Execution Strategy Error in VS2017 and Entity framework Core 2.0

查看:93
本文介绍了VS2017和实体框架Core 2.0中的自定义执行策略错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读使用Visual Studio 2017构建Web应用程序"(由Philip Japikse,Kevin Grossnicklaus和Ben Dewey撰写)并且陷入了困境.尝试使用Entity Framework Core为自定义执行策略创建类时,出现错误CR0246找不到类型或名称空间名称'ExecutionStrategyContext'(您是否缺少using指令或程序集引用?)"

I'm reading "Building Web Applications with Visual Studio 2017" (by Philip Japikse, Kevin Grossnicklaus, and Ben Dewey) and am getting stuck. When trying to create a class for a custome execution strategy with Entity Framework Core I get error CR0246 "The type or namespace name 'ExecutionStrategyContext' could not be found (are you missing a using directive or assembly reference?)"

该文本仅指出仅System和Microsoft.EntityFrameworkCore.Storage是必需的引用. EF Core 2.0文档似乎与文本匹配,但我无法使错误消失.

The text only states that only System and Microsoft.EntityFrameworkCore.Storage are required references. The EF Core 2.0 documentation seems to match the text but I cannot get the error to go away.

注意:本书使用Core和EF 1.1,而我使用的是2.0.但是我在任何文档中都没有看到任何暗示这一问题的信息.该类是:

Note: The book uses Core and EF 1.1 whereas I am using 2.0. But I don't see anything in any documentation that hints at this being the issue. The class is:

using System;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore;

namespace SpyStore.DAL.EF
{
    public class MyExecutionStrategy : ExecutionStrategy
    {
        public MyExecutionStrategy(ExecutionStrategyContext context) :
            base(context, ExecutionStrategy.DefaultMaxRetryCount, ExecutionStrategy.DefaultMaxDelay)
        {

        }

        public MyExecutionStrategy(ExecutionStrategyContext context, int maxRetryCount, TimeSpan maxRetryDelay) :
            base(context, maxRetryCount, maxRetryDelay)
        {

        }

        protected override bool ShouldRetryOn(Exception exception)
        {
            return true;
        }
    }
}

VS2017着重强调了ExecutionStrategyContext的两个实例.我尝试将它们更改为"ExecutionStrategyContext上下文",而不是"ExecutionStrategyContext上下文",但我不认为这是我想要的,但由于我的第一个参数是context,因此仍然出现错误.任何帮助表示赞赏!谢谢!

VS2017 is highlighting both instances of ExecutionStrategyContext as the issue. I've tried changing them to just 'ExecutionStrategy context' instead of 'ExecutionStrategyContext context' but I don't think this is what I want and I still get an error because my first parameter is context. Any help is appreciated! Thanks!

推荐答案

我无法提供文档链接,因为此时相关的EF Core API文档尚未更新,但是在v2.0中,ExecutionStrategyContext类已被ExecutionStrategyDependencies替换,并且ExecutionStrategy类现在具有以下构造函数:

I can't provide a documentation link because at this time the related EF Core API documentation is not updated yet, but in v2.0 the ExecutionStrategyContext class has been replaced with ExecutionStrategyDependencies and the ExecutionStrategy class now has the following constructors:

protected ExecutionStrategy(DbContext context, int maxRetryCount, TimeSpan maxRetryDelay);

protected ExecutionStrategy(ExecutionStrategyDependencies dependencies, int maxRetryCount, TimeSpan maxRetryDelay);

因此,更新后的示例应如下所示:

According to that, the updated sample should be something like this:

public class MyExecutionStrategy : ExecutionStrategy
{
    public MyExecutionStrategy(DbContext context) :
        this(context, DefaultMaxRetryCount, DefaultMaxDelay)
    {
    }

    public MyExecutionStrategy(DbContext context, int maxRetryCount, TimeSpan maxRetryDelay) :
        base(context, maxRetryCount, maxRetryDelay)
    {
    }

    public MyExecutionStrategy(ExecutionStrategyDependencies dependencies) :
        this(dependencies, DefaultMaxRetryCount, DefaultMaxDelay)
    {
    }

    public MyExecutionStrategy(ExecutionStrategyDependencies dependencies, int maxRetryCount, TimeSpan maxRetryDelay) :
        base(dependencies, maxRetryCount, maxRetryDelay)
    {
    }

    protected override bool ShouldRetryOn(Exception exception)
    {
        return true;
    }
}

这篇关于VS2017和实体框架Core 2.0中的自定义执行策略错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆