readd the virtual attribute

the virtual attribute is required to get the additional information
from the database. The reason why it failed when getting an object was
because lazy loading doesn't work on through WCF services.

To eagerly load the properties of an instance we have to use .include
in the context. In addition the ProxyCreationEnabled = false is
required because it will fail again. I'm not sure yet why exactly.
This commit is contained in:
Andreas Zweili 2018-06-29 23:31:13 +02:00
parent 4b3cfcd922
commit b30e57e007
11 changed files with 44 additions and 17 deletions

View File

@ -11,7 +11,10 @@ namespace Server.DB
{
using (Context ctx = new Context())
{
return ctx.Cities.ToList();
ctx.Configuration.ProxyCreationEnabled = false;
return ctx.Cities
.Include("Country")
.ToList();
}
}
public bool CreateCity(City city)

View File

@ -11,7 +11,12 @@ namespace Server.DB
{
using (Context ctx = new Context())
{
return ctx.Doctors.ToList();
ctx.Configuration.ProxyCreationEnabled = false;
return ctx.Doctors
.Include("Gender")
.Include("City")
.Include("Salutation")
.ToList();
}
}
public bool CreateDoctor(Doctor doctor)

View File

@ -11,7 +11,12 @@ namespace Server.DB
{
using (Context ctx = new Context())
{
return ctx.Exams.ToList();
ctx.Configuration.ProxyCreationEnabled = false;
return ctx.Exams
.Include("Patient")
.Include("Doctor")
.Include("Strain")
.ToList();
}
}
public bool CreateExam(Exam exam)

View File

@ -11,7 +11,11 @@ namespace Server.DB
{
using (Context ctx = new Context())
{
return ctx.FoodPlaces.ToList();
ctx.Configuration.ProxyCreationEnabled = false;
return ctx.FoodPlaces
.Include("City")
.Include("PatientAtFoodplaces")
.ToList();
}
}
public bool CreateFoodPlace(FoodPlace foodplace)

View File

@ -11,7 +11,11 @@ namespace Server.DB
{
using (Context ctx = new Context())
{
return ctx.PatientAtFoodPlaces.ToList();
ctx.Configuration.ProxyCreationEnabled = false;
return ctx.PatientAtFoodPlaces
.Include("Patient")
.Include("FoodPlace")
.ToList();
}
}
public bool CreateRelation(PatientAtFoodPlace patientAtFoodPlace)

View File

@ -11,7 +11,13 @@ namespace Server.DB
{
using (Context ctx = new Context())
{
return ctx.Persons.ToList();
ctx.Configuration.ProxyCreationEnabled = false;
return ctx.Persons
.Include("Gender")
.Include("City")
.Include("Salutation")
.ToList();
}
}
public bool CreatePerson(Person person)

View File

@ -17,7 +17,7 @@ namespace Server.Models
[DataMember]
public int ZipCode { get => _ZipCode; set => _ZipCode = value; }
[DataMember]
public Country Country { get => _Counry; set => _Counry = value; }
public virtual Country Country { get => _Counry; set => _Counry = value; }
public City() { }
public City (string name, int zipCode, Country country)

View File

@ -18,13 +18,13 @@ namespace Server.Models
[DataMember]
public DateTime Date { get => _Date; set => _Date = value; }
[DataMember]
public Doctor Doctor { get => _Doctor; set => _Doctor = value; }
public virtual Doctor Doctor { get => _Doctor; set => _Doctor = value; }
[DataMember]
public Person Patient { get => _Patient; set => _Patient = value; }
public virtual Person Patient { get => _Patient; set => _Patient = value; }
[DataMember]
public string Description { get => _Description; set => _Description = value; }
[DataMember]
public Strain Strain { get => _Strain; set => _Strain = value; }
public virtual Strain Strain { get => _Strain; set => _Strain = value; }
public Exam() { }
public Exam (Doctor doctor, Person patient, Strain strain, string description)

View File

@ -17,7 +17,7 @@ namespace Server.Models
[DataMember]
public int FoodPlaceID { get => _FoodPlaceID; set => _FoodPlaceID = value; }
[DataMember]
public City City { get => _City; set => _City = value; }
public virtual City City { get => _City; set => _City = value; }
[DataMember]
public string Streetname { get => _Streetname; set => _Streetname = value; }
[DataMember]
@ -27,7 +27,7 @@ namespace Server.Models
[DataMember]
public string Description { get => _Description; set => _Description = value; }
[DataMember]
public ICollection<PatientAtFoodPlace> PatientAtFoodPlaces
public virtual ICollection<PatientAtFoodPlace> PatientAtFoodPlaces
{
get => _PatientAtFoodPlaces;
set => _PatientAtFoodPlaces= value;

View File

@ -14,8 +14,8 @@ namespace Server.Models
public DateTime VistingDate { get; set; }
[DataMember]
public Person Person { get; set; }
public virtual Person Patient { get; set; }
[DataMember]
public FoodPlace FoodPlace { get; set; }
public virtual FoodPlace FoodPlace { get; set; }
}
}

View File

@ -23,15 +23,15 @@ namespace Server.Models
[DataMember]
public string LastName { get => _LastName; set => _LastName = value; }
[DataMember]
public Gender Gender { get => _Gender; set => _Gender = value; }
public virtual Gender Gender { get => _Gender; set => _Gender = value; }
[DataMember]
public Salutation Salutation { get => _Salutation; set => _Salutation = value; }
public virtual Salutation Salutation { get => _Salutation; set => _Salutation = value; }
[DataMember]
public string StreetName { get => _StreetName; set => _StreetName = value; }
[DataMember]
public string StreetNumber { get => _StreetNumber; set => _StreetNumber = value; }
[DataMember]
public City City { get => _City; set => _City = value; }
public virtual City City { get => _City; set => _City = value; }
[DataMember]
public ICollection<PatientAtFoodPlace> PatientAtFoodPlaces
{