0
У меня есть небольшая проблема. Я хочу проверить соединение двух таблиц.как инициировать внешний ключ при добавлении новой записи?
public class Patient:Person
{
//inheritance ID
public string insuranceNumber { get; set; }
public virtual PatientCard patientCard {get; set;}
}
public class PatientCard
{
public PatientCard()
{
this.patient = new HashSet<Patient>();
this.visit = new HashSet<Visit>();
}
public long id { get; set; }
public string bloodType { get; set; }
public string creationDate { get; set; }
public virtual ICollection<Patient> patient { get; set; }
public virtual ICollection<Visit> visit { get; set; }
}
Как инициировать внешний ключ при добавлении новой записи? Моя попытка выглядит так ...
var patient = new Patient {
ID=1, name = "Alicja", lastname = "Nowacka",
pesel = "89192232", address = "Szczecin",
phoneNumber = "11233332", insuranceNumber = "3211233123"
};
db.Persons.Add(patient);
db.SaveChanges();
var patientCard = new PatientCard {
bloodType = "A", creationDate = "2014-06-16",
patient= //**a reference to the key**
};
Спасибо!
Да, мой внешний ключ ID, я попытался непосредственно инициировать пациента = 1, но я получаю сообщение об ошибке «Не удается неявно преобразовать тип„INT“в«системе. Collections.Generic.ICollection " –
francesco123
Вы должны попробовать таким образом: patientCard.patient.add (пациент) –