Temel nesne özelliklerinin merkezi bir eşleştirmesini elde etmek için bir kandırmaca var mı? EntityTypeConfiguration kullanırken soyut sınıflar için bazı basit desen var mı.
HERHANGİ TAVSİYELER çok beğenildi. i cevaplar How to create and use a generic class EntityTypeConfiguration<TEntity> ve Dynamic way to Generate EntityTypeConfiguration : The type 'TResult' must be a non-nullable value typeEntityTypeConfiguration kullanırken soyut etki alanı modeli temel sınıfı <T>
public abstract class BosBaseObject
{
public virtual Guid Id { set; get; }
public virtual string ExternalKey { set; get; }
public byte[] RowVersion { get; set; }
}
public class News : BosBaseObject
{
public String Heading { set; get; }
}
public class NewsMap : EntityTypeConfiguration<News>
{
public NewsMap()
{
//Base Object Common Mappings
// How can we use a central mapping for all Base Abstract properties
}
}
// Something like this but very open to any suggestion....
public class BosBaseEntityConfig<T> : EntityTypeConfiguration<T>
{
public void BaseObjectMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
this.Property(t => t.Id).HasDatabaseGeneratedOption(databaseGeneratedOption: DatabaseGeneratedOption.None);
this.Property(t => t.RowVersion)
.IsRequired()
.IsFixedLength()
.HasMaxLength(8)
.IsRowVersion();
//Column Mappings
this.Property(t => t.Id).HasColumnName("Id");
}
}