在 DbContextOptions 中找不到 ApplicationDbContext

Can't find ApplicationDbContext in DbContextOptions

我是 .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)
    {

    }
}
}

您的问题是 ApplicationDbContext 不是模块,它是承包商的 class 名称。因此,将 ApplicationDbContext 替换为 ProjectDbContext。你的问题就解决了。

这是您的代码:

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)
    {

    }
}
}