We are facing a problem on EF. While lazy loading, sometimes the navigation property is returning null.
Note: I made this.Configuration.LazyLoadingEnabled = true;
on the db context
Model:
public class Student
{
public Int64 Id { get; set; }
public string Name { get; set; }
public string Gender { get; set; }
public Int64 Address_Id { get; set; }
[ForeignKey("Address_Id")]
public virtual Address Address { get; set; }
}
public class Address
{
public Int64 Id { get; set; }
public string Name { get; set; }
}
Database access:
Student oStudnet = context.Students.FirstOrDefault();
Int64 addressId= oStudnet.Address.Id
"null exception" on "oStudnet.Address.id" // Address is null here