问题描述
我有一个查询下面,但我想执行的include()跃跃欲试负载性能。操作有一个导航属性,用户(Action.User)
I have a query below, but I want to perform an Include() to eager load properties. Actions has a navigation property, User (Action.User)
1)我的基本的查询:
1) My basic query:
from a in Actions
join u in Users on a.UserId equals u.UserId
select a
2)第一次尝试:
2) First attempt:
from a in Actions.Include("User")
join u in Users on a.UserId equals u.UserId
select a
但Action.User是的不可以填充。
3)尽量渴望负荷用户进入查询之外在行动导航属性:
3) Try to eager load 'User' into the navigation property in action outside of query:
(from a in Actions
join u in Users on a.UserId equals u.UserId
select a).Include("User")
在LINQPad试图包含的我得到一个错误:
In LINQPad trying Include's I get an error:
System.Linq.IQueryable'不包含'包含'的定义,并没有扩展方法包含接受型System.Linq.IQueryable'的第一个参数可以发现(preSS F4添加using指令或程序集的引用)
'System.Linq.IQueryable' does not contain a definition for 'Include' and no extension method 'Include' accepting a first argument of type 'System.Linq.IQueryable' could be found (press F4 to add a using directive or assembly reference)
我想这是因为LINQ不支持包括()。
I think this is because LINQ doesn't support Include().
于是,我就在VS;查询2运行,但返回无人居住的用户属性。
问题3似乎扩展方法不存在,尽管它不行动本身不存在的查询。
So I tried in VS; query 2 runs, but returns unpopulated User property.Query 3 the extension method does not seem to exist, although it does exist on Action itself without the query.
推荐答案
我想通了,感谢反正建议。
解决的办法是这样做(第2次尝试在我的问题):
I figured it out, thanks for the suggestions anyway.The solution is to do this (2nd attempt in my question):
var qry = (from a in Actions
join u in Users on a.UserId equals u.UserId
select a).Include("User")
智能感知之所以没有表现出包括后查询是因为我需要使用以下内容:
The reason intellisense didn't show Include after the query was because I needed the following using:
using System.Data.Entity;
一切正常这样做。
Everything worked fine doing this.
这篇关于如何LINQ前$ P $与pssion语法工作包括()进行预先加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!