我正在做一个 ASP.NET CORE1.0.0的项目,我正在使用 EntityFrameworkCore。我有单独的程序集,我的项目结构如下:
ProjectSolution
-src
-1 Domain
-Project.Data
-2 Api
-Project.Api
在我的 Project.Api
是 Startup
类
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ProjectDbContext>();
services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<ProjectDbContext>()
.AddDefaultTokenProviders();
}
DbContext
在我的 Project.Data
项目中
public class ProjectDbContext : IdentityDbContext<IdentityUser>
{
public ProjectDbContext(DbContextOptions<ProjectDbContext> options) : base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var builder = new ConfigurationBuilder();
builder.SetBasePath(Directory.GetCurrentDirectory());
builder.AddJsonFile("appsettings.json");
IConfiguration Configuration = builder.Build();
optionsBuilder.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection"));
base.OnConfiguring(optionsBuilder);
}
}
当我尝试进行初始迁移时,我得到这个错误:
”你的目标项目‘ Project。Api’与您的迁移程序集‘ Project 不匹配。百科。要么更改目标项目,要么更改迁移程序集。 使用 DbContextOptionsBuilder 更改迁移程序集。例如选项。UseSqlServer (connect,b = > b. MigationsAssembly (“ Project。阿比”)。默认情况下,迁移程序集是包含 DbContext 的程序集。 通过使用 Package Manager Console 的 Default project 下拉列表,或者从包含迁移项目的目录中执行“ dotnet ef”,将目标项目更改为迁移项目
看到这个错误之后,我尝试执行位于 Project.Api
中的这个命令:
Dotnet ef —— start-Project. ./Project. Api —— Assembly“ . ./. ./1 Data/Project. Data”迁移添加 Initial
我得到了这个错误:
“选项‘ Assembly’的意外值‘ . ./. ./1 Domain/Project. Data’”
我不知道为什么会出现这个错误,当我尝试使用’-Assembly’参数执行命令时。
我无法从其他程序集创建初始迁移,我搜索了有关它的信息,但没有得到任何结果。
有人有类似的问题吗?