EF 试图创建泛型类型 table (TEntity)
EF trying to create generic type table (TEntity)
我执行(ef-core,代码优先)'by class' 配置,从通用基础 class 开始,像这样:
public class BaseEntityConfiguration<TEntity> : IEntityTypeConfiguration<TEntity>
where TEntity : BaseEntity
{
public virtual void Configure(EntityTypeBuilder<TEntity> builder)
{
var entityName = nameof(TEntity);
builder.ToTable(entityName);
}
}
add-migration
运行良好,但在 update-database
上它抱怨:
Cannot use table 'TEntity' for entity type 'Couche' since it is being
used for entity type 'Affaire' and potentially other entity types, but
there is no linking relationship. Add a foreign key to 'Couche' on the
primary key properties and pointing to the primary key on another
entity typed mapped to 'TEntity'.
为什么table'TEntity
'是泛型占位符TEntity
?
nameof(TEntity)
是字符串“TEntity”。你可能应该使用
var entityName = typeof(TEntity).Name;
相反。
我执行(ef-core,代码优先)'by class' 配置,从通用基础 class 开始,像这样:
public class BaseEntityConfiguration<TEntity> : IEntityTypeConfiguration<TEntity>
where TEntity : BaseEntity
{
public virtual void Configure(EntityTypeBuilder<TEntity> builder)
{
var entityName = nameof(TEntity);
builder.ToTable(entityName);
}
}
add-migration
运行良好,但在 update-database
上它抱怨:
Cannot use table 'TEntity' for entity type 'Couche' since it is being used for entity type 'Affaire' and potentially other entity types, but there is no linking relationship. Add a foreign key to 'Couche' on the primary key properties and pointing to the primary key on another entity typed mapped to 'TEntity'.
为什么table'TEntity
'是泛型占位符TEntity
?
nameof(TEntity)
是字符串“TEntity”。你可能应该使用
var entityName = typeof(TEntity).Name;
相反。