1

エンティティ構成 (マッピング) クラス間で共通のコードを、次のような基本クラスに抽象化しようとしています。

public class EntityWithIdTypeConfig<T>: EntityTypeConfiguration<T> where T: class, IEntityWithId
{
    public EntityWithIdTypeConfig()
    {            
    }

    public EntityWithIdTypeConfig(string tableName, string schemaName)
    {
        ToTable(tableName, schemaName);
        HasKey(t => t.Id);
    }
}

エンティティ クラスの例は次のようになります。

public partial class Parkade: IEntityWithId
{  
    public Parkade()
    {
        this.Zones = new List<Zone>();
    }
    public int Id { get; set; }
    public string Name { get; set; }
    public virtual ICollection<Zone> Zones { get; set; }
}

これはクラスによってマッピングされます:

public class ParkadeConfig : EntityWithIdTypeConfig<Parkade> 
{
    public ParkadeConfig(string tableName, string schemaName):base(tableName, schemaName)
    {
        HasRequired(t => t.Zones)
            .WithMany();
        Property(t => t.Name)
            .IsRequired()
            .HasMaxLength(50);
    }
}

クエリを実行すると、次のエラーが表示されます。

The key component 'Id' is not a declared property on type 'Parkade'.

Id は Parkade で明確に宣言されています。これはおそらくIdの実装であるためIEntityWithIdですか?私は何が間違っているのでしょうか?

4

0 に答える 0