ITPub博客

首页 > 应用开发 > > EF Core 一对一关系映射问题

EF Core 一对一关系映射问题

作者:wyfem 时间:2019-09-12 10:40:09 0 删除 编辑

在一个 .NET Core 项目中使用 Entity Framework Core 时遇到了下面的错误:

The child/dependent side could not be determined for the one-to-one relationship between 'BlogPost.ViewCount' and 'ViewCount'. To identify the child/dependent side of the relationship, configure the foreign key property

BlogPost 与 ViewCount 的 one-to-one 关系是这么配置的:

builder.HasOne(blogPost => blogPost.ViewCounter).WithOne();

modelBuilder.Entity<ViewCount>().HasKey(v => v.EntryId);

ViewCount 的主键 EntryId 保存的就是 BlogPost 的主键 Id 的值。

请问如何解决这个问题?

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2894/viewspace-3171164/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2008-12-22

  • 博文量
    73
  • 访问量
    33676