I have two object Classes
class Person
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set;}
public DateTime BirthDate { get; set; }
public bool IsMale { get; set; }
public byte[] Image { get; set; }
public byte[] RowVersion { get; set; }
public virtual Person Parent { get; set; }
public virtual ICollection<PhoneNumber> PhoneNumber { get; set; }
public virtual ICollection<Address> Addresses { get; set; }
public virtual PersonInfo PersonInfo { get; set; }
}
and :
class PhoneNumber
{
public enum PhoneType
{ Work, Mobile, Home };
public int id { get; set; }
public string phoneNumber { get; set; }
public PhoneType phoneType { get; set; }
public virtual Person Person { get; set; }
}
I added "virtual" keyword to my navigation properties to enable LazyLoading, then i added some codes for getting list of persons:
using (var newContext = new MyDbContext())
{
var selectedPerson = newContext.Persons.ToList();
}
But, when i run my project, i get the PhoneNumber being null! I thought if i add "virtual" keyword to my navigation properties then i get the PhoneNumber as well.. I got it all wrong?
newContext.Configuration.LazyLoadingEnabledequal totrue