I have an issue with the lazy loading behavior in EntityFramework 5. Here are my two models
public class Person {
[Key]
[Required]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public int? OfficeID { get; set; }
[ForeignKey("OfficeID ")]
public virtual Offices OfficeID_Offices { get; set; }
}
public class Offices
{
[Key]
[Required]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
//Navigation Properties
public virtual ICollection<Person> Person_OfficeID { get; set; }
}
Then I have the following function in my Controller
[HttpPost]
public Person Read(int intID)
{
Person objData = (from obj in objDB.Persons
where obj.ID == intID && !obj.Deleted
select obj).FirstOrDefault();
}
This controller method is called through a jquery $.Ajax call, which returns a JSON object. Since my foreign key OfficeID_Offices is virtual, I'd expect to only be loaded when I demand it explicitely. However when I look at my returned JSON Object, I can see that the entire Offices object is returned as well.
Lazy loading seems to be enabled in my DbContext, so I'm wondering how I could avoid having the whole Office object returned.
Thank you!