并转换为IQueryable的再次IEnumerable的执行查询? [英] does converting IQueryable to IEnumerable execute the query again?

查看:231
本文介绍了并转换为IQueryable的再次IEnumerable的执行查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的查询我需要返回的IEnumerable ,但我不知道,如果这个动作使查询再次执行?

In my query i need to return IEnumerable but i dont know if this action make the query to execute again?

VAR数据=库<人> .Find()AsEnumerable();

查找()收益的IQueryable 因为的IQueryable 继承的IEnumerable 。我怀疑 AsEnumerable 进行重复执行。

Find() returns IQueryable and because IQueryable inherits IEnumerable. I doubt if AsEnumerable make the repetitive execution.

我知道,
VAR数据=库<人方式> .Find()了ToList()执行查询两次。一个用于查找()和第二对了ToList()

I know that var data = Repository<Person>.Find().ToList() executes the query two times. One for Find() and second for Tolist()

推荐答案

一个IQueryable的的一个IEnumerable。没有转换,因此,没有任何一种事情的工作。

An IQueryable is an IEnumerable. There is no conversion, and therefore no work of any kind going on.

当您拨打该工作发生的GetEnumerator(),显式或通过调用的foreach 就可以了。

The work happens when you call GetEnumerator(), either explicitly or by invoking foreach on it.

此外,有您的确认 Repository.Find()了ToList() SQL调用两次?这听起来并不权利我。

Also, have you confirmed that Repository.Find().ToList() calls SQL twice? That doesn't sound right to me.

这篇关于并转换为IQueryable的再次IEnumerable的执行查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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