Reputation: 117
I am using EF 6 and have following
public class Title : EntityBase
{
public short Id { get; set; }
public string TitleName { get; private set; }
}
public abstract class EntityBase
{
public DateTime CreatedDate { get; set; }
}
And DbContext contains
public DbSet<Title> Titles { get; set; }
and also
modelBuilder.Entity<Title>().Map(m =>
{
m.MapInheritedProperties();
m.ToTable("Titles");
});
But while trying to access Titles, I get "The entity type EntityBase is not part of the model for the current context." After I run Update-Database in NuGet console, I see that table 'Titles' is created in database with all fields (id,titlename, createddate) as expected. I don't want to add EntityBase db set in DbContext if possible. Kindly help me to find a solution.
Upvotes: 1
Views: 1952
Reputation: 109119
MapInheritedProperties
is used to model a table-per-concrete type (TPC) mapping, a complete table for each class. You can do this, but then you have to configure the base class as well.
modelBuilder.Entity<EntityBase>();
However, I'd rather remove the MapInheritedProperties
statement and map each class individually. If you map a TPC mapping you'll never be able to map other inheritance associations between other classes of your model.
Upvotes: 3