I am working on a C# WPF project using Entity Framework code first.
I have a class that has an instance of another class as its member. I am trying to access the value of a property of the member class. I can get the value this way:
var com = context.MyParentClass.Where(p => (p.Identity == id)).Select(c =>
new
{
id = c.Identity,
PropertyValue = c.MyChildClass.PropertyValue
}
);
foreach(var item in com)
{
string xx = item.PropertyValue;
MessageBox.Show(xx);
}
But when I try to get the value without the select, the member class is always null:
var com = db.MyParentClass.SingleOrDefault(b => b.Identity == id);
string xx = com.MyChildClass.PropertyValue; //MyChildClass is null
MessageBox.Show(xx);
Does anyone know what is going on here? How do I get around the null-problem?