I created DbSets for my Raw Queries or StoredProcs in my dbcontext and used modelBuilder.Entity<_Entity>().HasNoKey().ToView(null)
under OnModelCreating. I use them in my controller like below:
_context._RTable.FromSqlRaw("exec sp_Run @thiscasenumber", casenumber).AsNoTracking().ToList();
It used to work fine on EF Core 3.1.
I recently upgraded my solution to 5.0. now when I try to do add-migration, the first time it does the job and everything works fine, but without making any change, after update-database, when I run add-migration again, it creates a migration and tries to delete these non-existing entities. migrationBuilder.DropTable(name: "_RTable");
Is there any way to prevent EF from dropping these "Tables" which do not exist?
Thanks
This is due to breaking changes in
.ToView(null)
behavior in .NET 5.Based on this post you should be using
.ToTable("ViewName", t => t.ExcludeFromMigrations())
to exclude enity set from migration.