小编典典

为什么不包含任何作用?

c#

我正在执行以下LINQ查询,但该查询有效,但未返回导航属性Person filled,我得到了null

public IEnumerable<SharePeople> GetSharePeopeByCarId(int carId)
{
    return from q in _context.Cars
           join s in _context.Shares 
               on q.CarId equals s.Car.CarId
           join p in _context.SharePeople.Include(p => p.Person) 
               on s.ShareId equals p.ShareId
           where q.CarId == carId
           select p;
}

我不知道为什么,因为当我执行常规的扩展方法时,_context.SharePeople.Include(p => p.Person)它就会起作用。


阅读 253

收藏
2020-05-19

共1个答案

小编典典

使用ste-fu方法并没有用,但是有了它的变体,我得以将其投入使用。

我猜格特·阿诺德(Gert Arnold)回答了为什么它不起作用,但是由于我知道了,所以这里的代码是:

var sharePeople = Context.SharePeople.Include("Person");

return sharePeople.Where(s => s.Shares.Car.CarId == carId);

2020-05-19