这是我的两个班级。首先填充SellPrice
个记录,然后使用SellPrice
记录从JSON请求插入的BuyPrice
记录中的信息。每条SellPrice
条记录都有BuyPrice
条记录。
我希望能够首先插入SellPrice
条记录,但即使我已将SellPrice
外键设置为可空,它仍然不会让我在没有查找的情况下保存SellPrice
条记录记录在BuyPrice
。
我希望能够每隔一秒左右不断删除和更新BuyPrice
JSON数据获取周期内的所有BuyPrice
条记录。
我对此非常陌生,希望能够使用数据注释而不是流利的方法来实现这一目标。
非常感谢。这让我疯了!
public class SellPrice
{
[Key]
public int Id { get; set; }
public DateTime EventDateTime { get; set; }
public string EventId { get; set; }
public String EventName { get; set; }
public string MarketId { get; set; }
public String MarketName { get; set; }
public String SelectionId { get; set; }
public String SelectionName { get; set; }
public String SellerName { get; set; }
public String SellPrice { get; set; }
public BuyPrice BuyPrice { get; set; }
public int? BuyPriceId { get; set; }
}
public class BuyPrice
{
[Key]
public int Id { get; set; }
public string MarketId { get; set; }
public string SelectionId { get; set; }
public float BuyPrice { get; set; }
}
注意:我更改了Model的名称以便更容易理解关系,因此错误消息指的是实际结构。原理是相同的 - 如何能够插入没有相应父记录的子记录。