add-migration 当实体有智能枚举时,添加迁移时报错
No suitable constructor was found for entity type 'Customer'. The following constructors had parameters that could not be bound to properties of the entity type: cannot bind 'customerLevel' in 'Customer(string name, CustomerLevel customerLevel)'.
解决方案:
在基础设施层添加配置文件
public class CustomerConfig : IEntityTypeConfiguration<Customer>
{
public void Configure(EntityTypeBuilder<Customer> builder)
{
builder.Property(p => p.CustomerLevel)
.HasConversion(
p => p.Value,
p => CustomerLevel.FromValue(p));
}
}
浙公网安备 33010602011771号