实体框架CLI无法从DbContext类型获取信息

时间:2018-11-12 12:34:36

标签: c# asp.net-core-mvc entity-framework-core

问题

在CLI上,我使用 dotnet dbcontext列表查看EF是否可以看到我的dbcontext( TestCoreASP.Data.TestCoreDbContext )。之后,我尝试使用 dotnet ef dbcontext info

从此DbContext查看信息。

然后我收到以下错误消息。但是,在我的代码的任何地方都没有创建一个名为FilterDescriptor的实体-这是什么?

  • EF CLI版本2.1.4

  • ASP.NET Core 2.1

错误消息

  

找不到适用于实体类型'FilterDescriptor'的合适构造函数。以下参数无法绑定到实体的属性:“ filter”,“ FilterScope”

DbContext模型

public class TestCoreDbContext : DbContext
    {
        public TestCoreDbContext(DbContextOptions options) 
            : base (options)
        {

        }

        public DbSet<Restaurantcs> Restaurants { get; set; }
    }

SQL命令类

 public class SqlRestaurantData : IResturantData
    {
        private TestCoreDbContext _context;

        public SqlRestaurantData(TestCoreDbContext context)
        {
            _context = context;
        }

        public Restaurantcs Add(Restaurantcs newRest)
        {
            _context.Restaurants.Add(newRest);
            _context.SaveChanges();
            return newRest;
        }

        public IEnumerable<Restaurantcs> GetAll()
        {
           return _context.Restaurants.OrderBy(r => r.Name);
        }

        public Restaurantcs GetSingle(int id)
        {
            return _context.Restaurants.FirstOrDefault(r => r.Id == id);
        }
    }

控制器属性

public class Restaurantcs : Controller
{
    public int Id { get; set; }
    [Display(Name="Resturant Name")]
    [Required, MaxLength(80)]
    public string Name { get; set; }
    public CuisineType Cuisine { get; set; }
}    

StartUP

   private IConfiguration _configuration;

        public Startup(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton<IGreeter, Greeter>();
            services.AddDbContext<TestCoreDbContext>(
                options => options.UseSqlServer(_configuration.GetConnectionString("TestCoreASP")));
            services.AddScoped<IResturantData, SqlRestaurantData>();


            services.AddMvc();
        }

0 个答案:

没有答案