当我尝试使用 EntityFramework Core 创建数据库时遇到了这个问题:
无法映射属性“Rating.RatingScores”,因为它属于“List”类型,它不是受支持的原始类型或有效的实体类型。显式映射此属性,或使用 '[NotMapped]' 属性或使用 'OnModelCreating' 中的 'EntityTypeBuilder.Ignore' 忽略它。
这是课程:
public class Rating
{
public int Id { get; set; }
public List<decimal> RatingScores { get; set; }
public decimal Score
{
set => Score = value;
get => Math.Round(RatingScores.Sum() / RatingScores.Count, 1);
}
}
Run Code Online (Sandbox Code Playgroud)