Reputation: 708
I've the following entity and DBContext in one assembly:
public class Notification
{
public virtual string Title { get; set; }
public virtual string Message { get; set; }
}
public class BaseModelContext : DbContext
{
/// <inheritdoc />
public BaseModelContext()
{
}
/// <inheritdoc />
public BaseModelContext(string connectionString, ContextMode mode) : base(connectionString, mode)
{
}
/// <inheritdoc />
public BaseModelContext(DbConnection connection, ContextMode mode) : base(connection, mode)
{
}
public virtual DbSet<Notification> Notifications { get; set; }
}
Now, in another assembly I want to derive from the Notification entity:
public class TransportNotification : Notification
{
public virtual int Position { get; set; }
}
public class TransportModelContext : MarvinDbContext
{
/// <inheritdoc />
public TransportModelContext()
{
}
/// <inheritdoc />
public TransportModelContext(string connectionString, ContextMode mode) : base(connectionString, mode)
{
}
/// <inheritdoc />
public TransportModelContext(DbConnection connection, ContextMode mode) : base(connection, mode)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<TransportNotification>().ToTable("TransportNotifications");
base.OnModelCreating(modelBuilder);
}
public virtual DbSet<Notification> TransportNotifications { get; set; }
}
My goal is that I have just one Notification table and one or more derivations of Notification in other tables with different DBContexts and schemas. Is this possible? And if so, does anyone how? In my tests the Notification table was also created by the migration tool (add-migration).
Upvotes: 3
Views: 43