0

I have an ASP.NET Core application. I have structured the application as multiple projects under the solution. In two of the projects I have 2 different contexts for the same database. The problem is I have a table I am using for auditing in both contexts, and this is causing a problem with migration.
My question is:
is there anyway I can make migration ignore creating this table in one of the contexts?

I am getting the error in the following line:

dbContext.Database.Migrate();
Sarahbe
  • 73
  • 13
  • I think you should review your system design. because if you ignore the Table for migration, you can't access that table in one of DbContext.you can create a new DbContext only for audit instead of one table in two DbContext. – Morteza Asadi Nov 24 '20 at 03:50
  • you are right, I think it is better to keep it in a separate context. thanks. – Sarahbe Nov 24 '20 at 08:45
  • Dublicate of https://stackoverflow.com/questions/22038924/how-to-exclude-one-table-from-automatic-code-first-migrations-in-the-entity-fram – Alex Yasinovsky Jun 17 '21 at 08:43

1 Answers1

0

in you dbContext you can ignore one or more table using model builder ignore and give the entity class type you want to ignore

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    base.OnModelCreating(modelBuilder);
    modelBuilder.Ignore<YourClassHere>();
}
Ahmed Aljaff
  • 129
  • 2
  • 9
  • 3
    ignore will exclude the entity from the model. What I want to do is only skip it on migration. – Sarahbe Nov 24 '20 at 02:22