首页 > 应用开发 > > EF Core 一对一关系映射问题
在一个 .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/ ,如需转载,请注明出处,否则将追究法律责任。