I am trying to use code-first within my existing project. I want to exclude existing entities from migrations I generate for new entities.
I have all models in separate class library project e.g. Data.Models and I am intending to use one context by creating another class library e.g. Infra.EF (model project is referenced in it).
This is how my DbContext looks like:
public DbSet<ExistingEntityOne> DataOfEntityOne { get; set; }
public DbSet<ExistingEntityTwo> DataofEntityTwo { get; set; }
public DbSet<NewEntity> NewData { get; set; }
Sorry if question isn't clear but I can add more information based on your feedback.
Thanks.
Comment new entities in your new DbContext
.
public DbSet<ExistingEntityOne> DataofEntityOne { get; set; }
public DbSet<ExistingEntityTwo> DataofEntityTwo { get; set; }
//public DbSet<NewEntity> NewData { get; set; }
Run following commands In power console manager:
Enable-Migrations
Add-Migration somename -IgnoreChanges
uncomment, commented entities.
public DbSet<ExistingEntityOne> DataofEntityOne { get; set; }
public DbSet<ExistingEntityTwo> DataofEntityTwo { get; set; }
public DbSet<NewEntity> NewData { get; set; }
Run following command:
Add-Migration someOtherName
You can find more, for EF Migrations here