小编okn*_*syl的帖子

EF Core - 无法确定导航表示的关系(一对多)

我正在尝试创建一个简单的一对多关系,但 Ef Core 不知何故无法识别它。我仍然是这方面的初学者,但我认为我是按照书本这样做的(完全定义了关系),所以我不明白为什么 EF Core 会抛出此错误:

无法确定“保险”类型的导航“资产.保险”所表示的关系。手动配置关系,或者使用“[NotMapped]”属性或使用“OnModelCreating”中的“EntityTypeBuilder.Ignore”忽略此属性。

这是我的两个模型:Asset.cs

public class Asset
{
    public int AssetId { get; set; }
    public string AssetName { get; set; }

    [ForeignKey("AssetTypeId")]
    public int AssetTypeId { get; set; }
    public AssetType AssetType { get; set; }
    
    public ICollection<AssetValue> AssetTypeValues { get; set; }
    
    public string Brand { get; set; }
    public string Model { get; set; }
    public string SerialNumber { get; set; }
    public string ProductNumber { get; set; }
    public DateTime PurchaseDate …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework entity-framework-core asp.net-core

3
推荐指数
1
解决办法
1万
查看次数