Entity Framework not loading related objects

后端 未结 3 1485
醉酒成梦
醉酒成梦 2021-01-05 15:07

I am new to Entity Framework, but might be misunderstanding something, or doing something wrong.

My code, to get me a list of tasks for a particular person :

3条回答
  •  醉酒成梦
    2021-01-05 15:33

    What you are looking for is .Include you use it like this

    var recordWithParentAttached = db.Tasks.Include(o => o.Person).Single(o => o.person_id == personId);
    

    with .Include your parents (or related records) will get attached and passed across while without they will be nulls.

提交回复
热议问题