Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i am hanging for while and i dont understand one thing...I will try to explain my issue...

I have model(Table) called FeuerwehrPerson and the class looks like that:

public partial class FeuerwehrPerson
{
    public FeuerwehrPerson()
    {
        this.BuchungenResultateList = new List<BuchungenResultate>();
        this.Notenspiegel=new Notenspiegel();
        this.Gemeinde=new Gemeinde();
    }

    public int FeuerwehrPersonId { get; set; }
    public string Anrede { get; set; }
    public string Vorname { get; set; }
    public string Nachname { get; set; }
    public System.DateTime Geburtstag { get; set; }
    public string Strasse { get; set; }
    public string Plz { get; set; }
    public string Ort { get; set; }
    public string Telefon { get; set; }
    public int GemeindeId { get; set; }
    public Nullable<int> NotenspielgelId { get; set; }
    public virtual ICollection<BuchungenResultate> BuchungenResultateList { get; set; }
    public virtual Gemeinde Gemeinde { get; set; }
    public virtual Notenspiegel Notenspiegel { get; set; }
}

In Feuerwehrperson are 2 Foreign Keys

  1. GemeindeId
  2. NotenspiegelId

and both of them are holding some values for a specific FeuerwehrPerson. Both Foreign Keys are not null in my FeuerehrPerson Table...

In my Controller i have a Edit Action...and i am searching for FeuerwehrPerson by id...thats working fine:

FeuerwehrPerson feuerwehrperson = db.FeuerwehrPerson.Find(id);   

When i am checking the values by using add Watch of feuerwehrperson Object there are some empty properties which shouldn´t be empty

The Object property Gemeinde should contain some values but its empty...also for Notenspiegel Object should contain SeminarA=true, SeminarB=true, SeminarC=true, rest is false but everything is false also NotenspiegelId and GemeindeId...but the Foreign Key references in Feuerwehrperson are not null...but why is it empty????

Please help me...

share|improve this question
    
Are you able to load the Gemeinde and Notenspiegel objects from the database themselves by their IDs? It sounds like the FeuerwehrPerson class is loading correctly, it's the related objects that aren't loading. Is this code-first or database-first? –  Adrian May 27 at 0:57
    
@Adrian yes i checked that now...i am able to load the Gemeinde and Notenspiegel objects by their IDs. Yes the related objects are not loading correctly...I am using code First –  Armando82 May 27 at 1:07
    
@Adrian my Gemeinde Model is a partial class –  Armando82 May 27 at 1:13
    
@Adrian i have created a console application and i generated my model by using Ado.net this time. If i am searching for a specific FeuerwehrPerson by id i am getting all related Objects populated with values back...thats really confusing now...why its not working in my case??? :( –  Armando82 May 27 at 1:32
    
I think you've disabled lazy loading on your context, which is why the related entity props remain null. –  Asad May 27 at 6:20
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.