实现IQueryable< T>的实例化类型可在.Net 4.0? [英] What instantiate-able types implementing IQueryable<T> are available in .Net 4.0?

查看:299
本文介绍了实现IQueryable< T>的实例化类型可在.Net 4.0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#on .Net 4.0的上下文中,是否有任何内置对象实现 IQueryable< T>

新在基本的.NET框架实现IQueryable。



IQueryable 是一个设计用于创建Queryable提供程序的接口,它允许通过构建可解析的表达式树来利用外部数据存储库来利用LINQ库。本质上,可查询需要一个上下文 - 关于你正在查询什么的信息。使用 new 创建任何IQueryable类型,不管是否可能,不会让你非常远。



也就是说,任何 IEnumerable 可以通过使用 AsQueryable()转换为 IQueryable 扩展方法。这在表面上创建了一个表面上类似的,但功能上非常的不同构造,当对平凡的 IEnumerable 对象使用LINQ方法时。这可能是您在没有设置实际的IQueryable提供程序的情况下访问的最丰富的可查询语言源。这种转换对于单元测试基于LINQ的算法非常有用,因为您不需要实际的数据存储,只需一个可以模仿它的内存数据列表。


Within the context of C# on .Net 4.0, are there any built-in objects that implement IQueryable<T>?

解决方案

IQueryable objects are produced by Queryable Providers (ex. LINQ to SQL, LINQ to Entities/Entity Framework, etc). Virtually nothing you can instantiate with new in the basic .NET Framework implements IQueryable.

IQueryable is an interface designed to be used to create Queryable providers, which allow the LINQ library to be leveraged against an external data store by building a parse-able expression tree. By nature, Queryables require a context - information regarding what exactly you're querying. Using new to create any IQueryable type, regardless of whether it's possible, doesn't get you very far.

That being said, any IEnumerable can be converted into an IQueryable by using the AsQueryable() extension method. This creates a superficially-similar, but functionally very different construct behind the scenes as when using LINQ methods against a plain IEnumerable object. This is probably the most plentiful source of queryables you have access to without setting up an actual IQueryable provider. This changeover is very useful for unit-testing LINQ-based algorithms as you don't need the actual data store, just a list of in-memory data that can imitate it.

这篇关于实现IQueryable&lt; T&gt;的实例化类型可在.Net 4.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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