I'm using EntityFramework Code-First with a context that has a model like:
public class Person {
public int ID {get;set;}
public string Name {get;set;}
}
with a context like
public class DataContext: DbContext {
public DbSet<Person> People {get;set;}
}
And this gets saved into DatabaseA. When I insert a new person, it auto-generates an ID for that person. I need to have a DatabaseB that has the exact same structure, but without the ID auto-generation. I want to transfer some records from DatabaseA to DatabaseB but without DatabaseB generating new IDs. I know that I can wrap
[DatabaseGenerated(DatabaseGeneratedOption.None)]
around the ID property, but I only want it to apply to DatabaseB without affecting DatabaseA.
So the only solution I've come up with so far is to have a new model
public class PersonB : Person {
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public new int ID { get; set; }
}
and a new context
public class DataContextB : DbContext {
public DbSet<PersonB> People {get;set;}
}
But this is a bit of a nuisance, as I'd have to maintain two sets of fairly identical models. Ideally, I'd like to be able to do something in using(var db = new DataContextB) { db. }