我正试图利用一个共同的实体类型来配置我所有实体的主要钥匙,以便每个衍生的组合类别不会重复。 我的所有实体都采用了一种共同的界面“意向”(即每个实体必须拥有一种类型的不动产)。
我的组合基阶层对此感到::
public class EntityConfiguration<TEntity> : EntityTypeConfiguration<TEntity>
where TEntity : class , IEntity {
public EntityConfiguration() {
HasKey( e => e.Id );
Property( e => e.Id ).HasDatabaseGeneratedOption( DatabaseGeneratedOption.Identity );
}
}
Each entity then has it s own specific configuration class extending this one like this:
public class CustomerConfiguration : EntityConfiguration<Customer> {
public CustomerConfiguration() : base() {
// Entity specific configuration here
}
}
这部法律汇编了罚款,但我面临的问题是,从目前来看,当第4条第1款(驻地协调员)试图建立这一模式时,我会提出以下例外:
System.InvalidOperationException was unhandled Message=The key component Id is not a declared property on type Customer . Verify that it has not been explicitly excluded from the model and that it is a valid primitive property. Source=EntityFramework
如果我改变客户配置类别,从实体TypeConfiguration<Customer>延伸;重复主要的主要配置,那么,客户组合就会奏效,但我失去分享共同配置的能力(主要动力)。
- Am I doing something wrong here?
- Is there another way to share common configuration between entities?
这里指的是其他课程:
public interface IEntity {
int Id { get; set; }
}
public class Customer : IEntity {
public virtual int Id { get; set; }
public virtual string name { get; set; }
}
Thanks!