How to create 2 dbsets with the same type in Entity Framework code first?
The short answer is that you can't do this. Consider this line of code:
var flight = context.Set<Flight>().Where(f => f.FlightNumber == "123");
How does it know which set to use to get the data?
Probably the simplest workaround would be to inherit the Flight
class and use that for your other DbSet
:
public class ArchiveFlight : Flight
{
}
And your context:
public class FlightsDatabase :DbContext
{
public DbSet<Flight> Flights { get; set; }
public DbSet<ArchiveFlight> FlightsArchive { get; set; }
public DbSet<Passanger> Passengers { get; set; }
}
The bonus of doing this is that you can now add properties to your archived flights, such as the date it was archived:
public class ArchiveFlight : Flight
{
public DateTime DateArchived { get; set; }
}