问题
I recently upgraded to .net 5.0 and I use entity framework. I edited a database model by adding an extra field and ran my normal script in powershell
dotnet ef migrations add mig_name
Since the C# upgrade though the upgrade script is trying to add all my Keyless models that I use for Stored Procs to the ModelSnapshot file. And what that means is that it tries to then drop these tables from the database even though they don't exist.
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "SimpleStoredProc");
migrationBuilder.DropTable(
name: "StoredProc2");
migrationBuilder.DropTable(
name: "StoredProc3");
}
etc.
I have read the latest article on the subject and tried adding [Keyless] above my model definitions. This didn't fix it.
I can manually edit the ModelSnapshot file and edit out all the Keyless tables, but when I ran another migration script they are all put back there.
My DbContext file looks like
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<SimpleStoredProc>(eb => { eb.HasNoKey(); eb.ToView(null); });
}
I've spent a day on this! Driving me mad. Has anyone else upgraded from Net core 3.1 to .net 5.0 and had problems with EF migrations?
来源:https://stackoverflow.com/questions/65085351/net-5-0-ef-migrations-adding-stored-proc-models-to-modelsnapshot