initally using code first approch i created db and tables . inserted few records using the form
now i am trying to use seed method in configuration.cs to added more test data .
but having issue with key. below is patient and patient address model having 1 - 1 relationship
patient model
public int PatientID { get; set; }
[Display(Name = "Last Name")]
public string LastName { get; set; }
[Display(Name = "First Name")]
public string FirstName { get; set; }
public float age { get; set; }
public string Mobile { get; set; }
public virtual PatientAddress PatientAddress { get; set; }patient address model
[Key]
[ForeignKey("Patient")]
public int PatientID { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string State { get; set; }
public virtual Patient Patient { get; set; }when adding records in the address using seed method how do i refer the patientid?
seed method of config.cs
context.PatientAddress.AddOrUpdate(
p => p.PatientID,
new PatientAddress() { Address1 = "Address1 ", Address2 = "", City = "City1", State = "State 2" },
new PatientAddress() { Address1 = "Address1 22 ", Address2 = "Address2 44", City = "City2", State = "State 33" },
new PatientAddress() { Address1 = "Address1 777 ", Address2 = "Address2 66", City = "City3", State = "State 44" },
new PatientAddress() {Address1 = "Address1 44 ", Address2 = "Address2 477", City = "City4", State = "State 232" }
);