简体   繁体   English

使用IQueryable的缺点!

[英]disadvantages of using IQueryable !

Is there are any performance issues related to using IQueryable ? 是否存在与使用IQueryable相关的性能问题?
Besides, if I use a cursor instead of using IQueryable (is that better) . 此外,如果我使用游标而不是IQueryable (那会更好)。
IQueryable vs IEnumerable vs IList ? IQueryable vs IEnumerable vs IList
I use MongoDB as my database . 我使用MongoDB作为数据库。 Thank you 谢谢

Those are just different interfaces, and as interfaces doesn't contain any implementation it doesn't matter for performance which you use. 这些只是不同的接口,并且由于接口不包含任何实现,因此与所使用的性能无关。

When you loop over the values the enumerator of the actual class will be used, regardless of which interface you use to access it. 当您遍历值时,将使用实际类的枚举数,无论您使用哪个接口访问它。

I don't know how the MongoDB C# binding works, but describe how it usually works: 我不知道MongoDB C#绑定的工作原理,但描述一下它通常如何工作:

When using IQueryable an expression tree is constructed, then translated into a format the database can understand and then executed in the database-server. 使用IQueryable将构造一个表达式树,然后将其转换为数据库可以理解的格式,然后在数据库服务器中执行。

This typically has a small overhead(construct expression tree and translate it) compared to directly writing queries in the format the database understands. 与直接以数据库可理解的格式编写查询相比,这通常具有较小的开销(构造表达式树并对其进行翻译)。

With IEnumerable delegates are used, instead of expressions. IEnumerable一起使用委托,而不是表达式。 It needs to iterate over the complete dataset and then filters using Linq-To-Objects. 它需要遍历完整的数据集,然后使用Linq-To-Objects进行过滤。 This is much slower. 这要慢得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM