I am developing a plugin application with EF6, code first.
I have one main context with an object called User :
public class MainDataContext : DbContext { public MainDataContext(): base("MainDataContextCS") {} public DbSet<User> Users { get; set; } }
And then another context for PluginX, in another project that references the base:
public class PluginDataContext : DbContext { public PluginDataContext () : base("MainDataContextCS") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.HasDefaultSchema("PluginX"); base.OnModelCreating(modelBuilder); } public DbSet<Booking> Bookings { get; set; } }
And this neatly creates the PluginX.Bookings table in the same database (same connection string).
The problem is that the Booking object contains a link to the User object:
public class Booking { public int Id { get; set;} public virtual User CreationUser { get; set;} public BookingStatus Status { get; set; } }
And when you start Add-Migration for the context of the plugin, EF will try to create another User object called PluginX.User .
How can this be solved? Is there a way to share a common entity in another DbContext ?
source share