【发布时间】:2021-12-18 19:06:05
【问题描述】:
我有具有 LinkedArticles 能力的表格文章,所以基本上当用户预览时,例如“Iphone 13”链接文章可能是“Iphone Charger”或“AirPads”等。
这是我的实体:
public class Article : BaseEntity<long>, IDeleted
{
public long? BrandId { get; set; }
public Brand Brand { get; set; }
public string Title { get; set; }
public string ShortDescription { get; set; }
public string Description { get; set; }
public ICollection<LinkedArticle> LinkedArticles { get; set; }
public bool Deleted { get; set; }
}
链接的文章如下所示:
public class LinkedArticle : BaseEntity<long>, IDeleted
{
public long ArticleId { get; set; }
public Article Article { get; set; }
public long RelatedArticleId { get; set; }
public Article RelatedArticle { get; set; }
public bool Deleted { get; set; }
}
所以基本上我想在这个表中保存相关文章 LinkedArticles 因此,例如文章 id 5 可以有一些与 id 5 相关的不同文章。
但是当我尝试添加迁移时,出现以下错误:
无法确定导航所代表的关系 'ICollection' 类型的'Article.LinkedArticles'。任何一个 手动配置关系,或使用 '[NotMapped]' 属性或使用 'EntityTypeBuilder.Ignore' 'OnModelCreating'。
这里发生了什么?我将ICollection<LinkedArticle> 添加到Article.cs 是因为我希望能够从文章实体中查询链接的文章。
【问题讨论】:
标签: c# linq .net-core entity-framework-core entity-framework-6