So lets you pretend in your Model class (whichever you want to call it that inherits from DbContext) and you override OnModelCreating
. You have a base class called DBDateTime
and let's say it looks something like this ->
public class DbDateTime
{
public DateTimeOffset CreatedDateTime { get; set; }
public DateTimeOffset LastModifiedDateTime { get; set; }
}
and then you have a class that inherits from it --->
public class MyTable : DbDateTime
{
public string Id{ get; set; }
public string prop1{ get; set; }
}
in your model and your OnModelCreating
you would have something like ->
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<MyTable>(entity =>
{
entity.Property(x => x.CreatedDateTime).Metadata.AfterSaveBehavior = PropertySaveBehavior.Ignore;
})
}
This is fine for one table that inherits from a set of properties but if you have 10 tables that inherit from such a class is there a way to use some sort of inheritance with property generation in ef core 2.0? I would love to write code once and set property generation rules for the base class so I don't have to write it over and over again per class that inherits from that base class.