asp.net mvc - Unable to insert record in main table without lookup record even with null foreign key MVC EF -


here's 2 classes. sellprice records populated first , using information in sellprice records buyprice records inserted json request. there many sellprice records each buyprice record.

i want able have sellprice records inserted first though have set sellprice foreign key nullable still wont let me save sellprice records without lookup record in buyprice.

i want able delete , update buyprice records on buyprice json data fetch cycle every second or so.

i new , able using data annotations rather fluent method.

many thanks. it's driving me nuts!

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; } } 

note: have changed names of model make easier understand relationship the error message referring actual structures. principle same - how able insert child records no corresponding parent record.

enter image description here


Comments