I'm trying to create EF code first with multiple contexts. One context for for StaffContext (HR) and the other is ,ShippingContext.
Is the idea of having multiple contexts has any advantages ? Cause I feel it is complex to construct.
How do we construct the entities ? Define all in base context or in each separate context ?
In these contexts, I need access to Staff entity which when I try to "update-database" will gives me an error since the Staff entity already exist in other context. Is the fact that I have same entity in different context is wrong design ?
This is what I have at the moment :
public class StaffContext : BaseContext<StaffContext>
{
public DbSet<StaffPosition> StaffPositions { get; set; }
public DbSet<Staff> Staffs { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
public class ShippingContext : BaseContext<ShippingContext>
{
public DbSet<Armada> Armadas { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<Shipment> Shipments { get; set; }
public DbSet<ShipmentDetail> ShipmentDetails { get; set; }
public DbSet<ShipmentHandler> ShipmentHandlers { get; set; }
public DbSet<ShipmentOrder> ShipmentOrders { get; set; }
public DbSet<ShipmentOrderDetail> ShipmentOrderDetails { get; set; }
public DbSet<Staff> Staffs { get; set; }
public DbSet<Pangkalan> Pangkalans { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
Thanks a lot in advance.