首页 > 解决方案 > 如果相关数据在插入时为空,则询问是否可以在相关数据中插入主键

问题描述

我只是在徘徊,我将我的数据插入到我试图不插入该模型的相关模型中的关系数据中。结果为空,并且在 db 中没有密钥保存。

它的一对一关系

C# ef 核心

我在json中试过这个

{
  testingName: "123231",
  testingRelatedData: {
    testingNameRelated: "asdasd"
 }
}

并且代码是在上下文中添加的一种正常方式。

class model {
  public int modelid {get; set;}
  public string testingName  {get; set;}
  public virtual testingNameRelated testingNameRelated { get; set; }
}
class testingNameRelated{
  public int id {get; set;}
  public string testingNameRelated{get; set;}

  public model model {get; set;}
  public int modelid {get; set;}
}

context.testing.add(model)

谢谢

标签: asp.net-web-apientity-framework-6

解决方案


推荐阅读