【发布时间】:2026-02-20 19:20:06
【问题描述】:
我正在执行以下 LINQ 查询,该查询有效但不返回已填充的导航属性 Person,我得到 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) 这样的常规扩展方法时,它可以工作。
【问题讨论】:
-
您确定您符合条件
s.ShareId equals p.ShareId吗? -
是的,因为我得到了一条记录,但
Personproperty 为空,所有其他值都可以。 -
我在
SharePeople中有一个Personproperty。 -
有你的上下文
Configuration.LazyLoadingEnabled = false?
标签: c# linq entity-framework extension-methods