.net 5.0 EF migrations adding stored proc models to ModelSnapshot

久未见 提交于 2021-01-07 02:40:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!