Entity framework 6.0 dotnet 4.5
This query collects one record in DB. If it does not exist in DB, creates it and load it.
using (DBContext sq = new DBContext())
{
wfQandA a = sq.wfQandAs.FirstOrDefault(x => x.wfStepID == psid && x.QuestionID == Qid);
if (a == null)
{
wfQandA a1 = new wfQandA();
a1.wfStepID = psid;
a1.QuestionID = Qid;
a1.OverRiden = false;
sq.wfQandAs.Add(a1);
sq.SaveChanges();
a = sq.wfQandAs.FirstOrDefault(x => x.wfStepID == psid && x.QuestionID == Qid);
}
wfStep test= a.wfStep;
}
If record exists in DB, "a" is loaded with dynamic proxies: a ={System.Data.Entity.DynamicProxies.wfQandA_F674B4C0C963114E42A6AF320A5E9E682CF1DA6534BE8FF2F36989FC9BA80D85} I can access all sub tables.
If record does not exist, record is created, and a is queried again. however is this case 'a' is not loaded with dynamic proxy a= {CALMO_DataModels.Models.wfQandA} and all associated sub table are null.
I tried to reload a using SingleOrDefault directly with newly created id, same issue.
What could be causing entity not to load with dynamic proxies?
Include. That's better anyway because it doesn't trigger lazy loading which (apparently) happens when the record exists.