学海无涯

导航

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));
  }
}

  

 

posted on 2023-09-15 17:04  宁静致远.  阅读(6)  评论(0编辑  收藏  举报