Unfortunately ef core does not support TPC-pattern, but we need this kind of behaviour. I′ve wrote an interface which is called IBase and each entity implements this interface:
public interface IBase
{
Guid Id { get; set; }
[Column(TypeName = "datetime2")]
DateTime CreateDate { get; set; }
[Required]
[StringLength(255)]
string CreateUser { get; set; }
bool Deleted { get; set; }
}
I want to get rid of Annotations to use the Fluent API configuration instead. But I have about 20 different entities and 7 Base-Values and I don′t want to make the same configuration over and over again:
modelBuilder.Entity<SomeEntity>()
.Property(e => e.CreateDate)
.HasColumnType("datetime2(2)")
.IsRequired();
Any ideas how to configure each Base-Property once for all entities implementing IBase?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…