ITPub博客

首页 > 应用开发 > > 升级至 .net core 3.0 遇到的 ef core 一对一映射关系

升级至 .net core 3.0 遇到的 ef core 一对一映射关系

作者:huzhizhong 时间:2019-09-02 10:26:30 0 删除 编辑

之前用的是 .net core 2.2 ,一对一映射关系是这么配置的

builder.OwnsOne(post => post.ViewCount).HasForeignKey(vc => vc.EntryId);

升级至 .net core 3.0 之后,不支持 OwnsOne 之后直接跟 HasForeignKey ,必须要加 WithOwner ,于是改为:

builder.OwnsOne(post => post.ViewCount).WithOwner().HasForeignKey(vc => vc.EntryId);

但运行报错

The type 'ViewCount' cannot be configured as non-owned because an owned entity type with the same name already exists

请问如何解决这个问题?

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

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    107
  • 访问量
    921