0
我尝试添加使用流利的API的配置如下:类型“短”必须是引用类型,以便在通用型使用它作为参数“TTargetEntity”
public class PeriodTypeMappings: EntityTypeConfiguration<PeriodType>
{
public PeriodTypeMappings()
{
this.HasKey(p => p.PeriodTypeId);
this.Property(p => p.PeriodTypeName).HasMaxLength(value: 25);
this.HasRequired(p => p.PeriodTypeName);
this.HasRequired(p => p.NumberOfPartitions);//compile error
}
}
但我得到以下情况除外:
类型“短”必须是为了在通用类型或方法 “EntityTypeConfiguration.HasRequired使用它作为 参数“TTargetEntity”引用类型(例pression>)'
在最后一行this.HasRequired(p => p.NumberOfPartitions);
发生异常,其中NumberOfPartitions
是short类型的异常。
为什么会发生这种情况,以及如何解决这个问题,我试着说这个字段是必需的。