询问在插入相关数据是否为空时是否可能在相关数据中插入主键

时间:2019-06-03 06:19:38

标签: asp.net-web-api entity-framework-6

我只是在流浪,我想将我的数据插入关系数据中,但我试图不插入该模型的相关模型中。结果为null,并且在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)

谢谢

0 个答案:

没有答案