DEV Community

freecoderzhaoshuai
freecoderzhaoshuai

Posted on

Scaffold new tables and keep the existed ones?

I wish there were a built-in way to add entities and update an existing context, but there doesn't seem to be. I overcame this by using the --context option in the package manager console and just gave it a temporary name, e.g. --context TempContext. This worked and generated the new table and the temp context. Then I just copied the public virtual DbSet NewEntityType { get; set; } property and the modelBuilder.Entity(entity => block from the OnModelCreating method in the temp context to my existing one. After that, I deleted the temp context. It's pretty straightforward.

Top comments (0)