Ich mache ein Projekt in ASP.NET CORE 1.0.0 und ich verwende EntityFrameworkCore. Ich habe getrennten Baugruppen und meine Projektstruktur sieht wie folgt aus:Hinzufügen von Migration mit anderen Assembly
ProjectSolution
-src
-1 Domain
-Project.Data
-2 Api
-Project.Api
In meinem Project.Api
ist die Startup
Klasse
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ProjectDbContext>();
services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<ProjectDbContext>()
.AddDefaultTokenProviders();
}
Die DbContext
in meinem Project.Data Projekt ist
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);
}
}
Wenn Ich versuche, die anfängliche Migration zu machen, bekomme ich diesen Fehler:
"Your target project 'Project.Api' doesn't match your migrations assembly 'Project.Data'. Either change your target project or change your migrations assembly. Change your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly("Project.Api")). By default, the migrations assembly is the assembly containing the DbContext. Change your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing "dotnet ef" from the directory containing the migrations project."
Nachdem ich diesen Fehler zu sehen, habe ich versucht, diesen Befehl in Project.Api
befindet auszuführen:
dotnet ef --startup-project ../Project.Api --assembly "../../1 Data/Project.Data" migrations add Initial
und ich habe diesen Fehler:
"Unexpected value '../../1 Domain/Project.Data' for option 'assembly'"
I don t know why I get this error, when I try to execute the command with the
-assembly` Parameter.
Ich kann keine erste Migration von anderen Assembly erstellen und ich habe nach Informationen darüber gesucht, aber keine Ergebnisse erhalten.
Hat jemand ähnliche Probleme?
Haben Sie die Dokumentation gelesen? https://docs.efproject.net/en/latest/miscellaneous/cli/dotnet.html?highlight=workaround#targeting-class-library-projects-is-not-supported – Tseng
Ja, aber ich habe das nicht behoben Fehler, ich habe verschiedene Optionen von Befehlen mit --startup-project und --assed versucht, aber ich habe nichts bekommen – kdar
Nicht benutzen --assembly. Das ist ein internes Implementierungsdetail, das in der Hilfe-Nachricht versteckt sein sollte, aber trotzdem auftaucht wegen https://github.com/aspnet/EntityFramework/issues/5188 – natemcmaster