I have a question about inheriting a custom DbContext
class.
I have created a custom DbContext
class called BaseContext
in namespace 1 using C# Ado.net entity model generator as shown here:
namespace NS1
{
public partial class BaseContext: DbContext
{
public BaseContext(): base("name=BaseContext")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<PLAYERS> PLAYERS { get; set; }
}
}
And in the other namespace, I have created another context which uses the same database but its some other tables.
namespace NS2
{
public partial class ExtensionContext: DbContext
{
public ExtensionContext(): base("name=ExtensionContext")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<CRICKET_PLAYERS> CRICKET_PLAYERS { get; set; }
}
}
Now I am in a situation to use PLAYERS
DbSet in the ExtensionContext
. I have tried to inherit the BaseContext
from ExtensionContext
and pass the ExtensionContext
connection string to the BaseContext
constructor which in turn sends to the DbContext
.
But during implementation I get an exception stating
The PLAYERS name does not exist in the current ExtensionContext
Please give me some insight into the possibility of reusing the existing DbSet
types in the extended context.
Thanks in advance