Reputation: 3012
(Version 7.0.0-beta5)
Is there a way to exclude a class or DbSet
from being included in the migration add
command evaluation?
The database I'm building will include some tables that are replicated from another environment. They need to be included in the DbContext so they can be queried and joined, but should never have migrations generated for them.
What's the best practice in this situation?
Upvotes: 2
Views: 1471
Reputation: 3012
As of beta6, what works best for me is ensuring that the DbContextModelSnapshot
includes mappings for the replicated entities.
Once the entities are mapped the migration scaffolding process compares the model snapshot to the entities to determine if there are changes. Since the entity classes match the model snapshot, no migrations are generated relating to those entities. When the DbContextModelSnapshot
is regenerated and overwritten, it keeps the same mappings because there were no changes.
Also in the future there may be a feature to help out with this, as seen in this issue - no promises though, and not for the first release. https://github.com/aspnet/EntityFramework/issues/2725
Upvotes: 4
Reputation: 8932
You can manually remove the creations or alterations from the migration file.
Upvotes: 2