【问题标题】:Can't find ApplicationDbContext in DbContextOptions在 DbContextOptions 中找不到 ApplicationDbContext
【发布时间】:2021-09-25 03:37:52
【问题描述】:

我是 .net 框架的新手,我被这个 ApplicationDbContext 卡住了,这是我的代码示例:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace Rocky.Data
{
public class ProjectDbContext:DbContext
{
    public ProjectDbContext(DbContextOptions<ApplicationDbContext> options): base(options)
    {

    }
}
}

【问题讨论】:

标签: .net asp.net-core .net-core asp.net-core-mvc


【解决方案1】:

您的问题是 ApplicationDbContext 不是一个模块,它是承包商的类名。所以用 ProjectDbContext 替换 ApplicationDbContext。并且您的问题得到解决。

这是你的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace Rocky.Data
{
public class ProjectDbContext:DbContext
{
    public ProjectDbContext(DbContextOptions<ProjectDbContext> options): base(options)
    {

    }
}
}

【讨论】:

    猜你喜欢
    • 2017-02-24
    • 2018-01-13
    • 2020-04-19
    • 2015-07-21
    • 1970-01-01
    • 2023-03-18
    • 2020-10-13
    • 2022-01-16
    • 1970-01-01
    相关资源
    最近更新 更多