是否可以在使用 EF Core 的项目中使用枚举列表来存储数据?
我的枚举:
public enum AudienceType
{
Child,
Teen,
[Display(Name ="Young Adult")]
YoungAdult,
Adult,
Elderly
}
Run Code Online (Sandbox Code Playgroud)
使用枚举的类:
public class Restaurant
{
public int Id { get; set; }
[Required, StringLength(80)]
public string Name { get; set; }
[Display(Name="Select the target audiences")]
public List<AudienceType> AudienceTypes { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行时add-migration AudienceType,出现以下错误:
PM> add-migration AudienceType
Build started...
Build succeeded.
System.InvalidOperationException: The property 'Restaurant.AudienceTypes' could not be mapped, because it is of type 'List<AudienceType>' which is not a …Run Code Online (Sandbox Code Playgroud)