Add mappings for the PatientAtFoodPlaceDB

I have no idea why we need this but shit keeps breaking without it :)
This commit is contained in:
Andreas Zweili 2018-08-07 22:45:45 +02:00
parent afe5d23865
commit 3ce42280d3
1 changed files with 21 additions and 0 deletions

View File

@ -26,6 +26,27 @@ namespace Server.DB
{
using (Context ctx = new Context())
{
var patient = ctx.Persons.FirstOrDefault(p => p.PersonID == patientAtFoodPlace.Patient.PersonID);
var foodplace = ctx.FoodPlaces.FirstOrDefault(f => f.FoodPlaceID == patientAtFoodPlace.FoodPlace.FoodPlaceID);
var pcity = ctx.Cities.FirstOrDefault(c => c.CityID == patient.City.CityID);
var fcity = ctx.Cities.FirstOrDefault(c => c.CityID == patientAtFoodPlace.FoodPlace.City.CityID);
var pcountry = ctx.Countries.FirstOrDefault(c => c.CountryID == pcity.Country.CountryID);
var fcountry = ctx.Countries.FirstOrDefault(c => c.CountryID == fcity.Country.CountryID);
var salutation = ctx.Salutations.FirstOrDefault(s => s.SalutationID == patient.Salutation.SalutationID);
var gender = ctx.Genders.FirstOrDefault(g => g.GenderID == patient.Gender.GenderID);
ctx.Cities.Attach(pcity);
ctx.Cities.Attach(fcity);
ctx.Countries.Attach(pcountry);
ctx.Countries.Attach(fcountry);
ctx.Genders.Attach(gender);
ctx.Salutations.Attach(salutation);
ctx.Persons.Attach(patient);
ctx.FoodPlaces.Attach(foodplace);
patientAtFoodPlace.FoodPlace = foodplace;
patientAtFoodPlace.Patient = patient;
ctx.PatientAtFoodPlaces.Add(patientAtFoodPlace);
ctx.SaveChanges();
}