为什么 Include 没有任何效果? [英] Why doesn't Include have any effect?

查看:36
本文介绍了为什么 Include 没有任何效果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行以下 LINQ 查询,该查询有效但不返回已填充的导航属性 Person,我得到 null.

I am doing the following LINQ Query which works but doesn't return the navigation property Person filled, I get 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) 这样的常规扩展方法时,它可以工作.

I have no idea why, since when I do the regular extension method like _context.SharePeople.Include(p => p.Person) it works.

推荐答案

使用 ste-fu 方法没有奏效,但通过它的变体我能够将其投入使用.

Using ste-fu approach it did not worked, but with a variation of it I was able to put it to work.

我猜 Gert Arnold 回答了为什么它不起作用,但因为我在这里工作的是代码:

I guess Gert Arnold answered why it does not work, but since I got it working here is the code:

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

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

这篇关于为什么 Include 没有任何效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆