小编Edu*_*scu的帖子

无法映射属性“PropertyName”,因为它的类型为“List<decimal>”

当我尝试使用 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)

c# entity-framework-core

10
推荐指数
2
解决办法
2万
查看次数

标签 统计

c# ×1

entity-framework-core ×1