iqueryable

Using IQueryable with Linq

懵懂的女人 提交于 2019-11-26 11:58:02
What is the use of IQueryable in the context of LINQ? Is it used for developing extension methods or any other purpose? Reed Copsey Marc Gravell's answer is very complete, but I thought I'd add something about this from the user's point of view, as well... The main difference, from a user's perspective, is that, when you use IQueryable<T> (with a provider that supports things correctly), you can save a lot of resources. For example, if you're working against a remote database, with many ORM systems, you have the option of fetching data from a table in two ways, one which returns IEnumerable<T>

Expose IQueryable Over WCF Service

这一生的挚爱 提交于 2019-11-26 11:37:54
问题 I\'ve been learning about IQueryable and lazy loading/deferred execution of queries. Is it possible to expose this functionality over WCF? I\'d like to expose a LINQ-to-SQL service that returns an IQueryable which I can then perform additional queries on at the client, and finally execute using a .ToList(). Is OData format applicable at all in this context? If possible, what is the term for this technique and what are some good tutorials I can follow? Thank you. 回答1: You should check WCF Data

IQueryable & Repositories - take 2?

对着背影说爱祢 提交于 2019-11-26 11:25:39
问题 I have to admit I have been carrying the \"Repository should not return IQueryable\" banner because it is harder to test. I have been influenced by the answers to other questions like this and this. This morning I\'ve been reading ScuttGu\'s blog about ASP.NET vNext where he details Model Binding using a SelectMethod that seems to rely on IQueryable for paging and sorting. Do you think this will force us to reconsider the role IQueryable plays in repositories? 回答1: DDD Repository should

ASP.MVC: Repository that reflects IQueryable but not Linq to SQL, DDD How To question

匆匆过客 提交于 2019-11-26 09:34:09
问题 I want to create a DDD repository that returns IQueryable Entities that match the Linq to SQL underlying classes, minus any relations. I can easily return Entities minus the relations with a Linq select new {field, field, ... } projection. How do I code the Repository Entity class? How would I return an object from the repository having the repository class not the Linq to SQL class and still fill it with multiple entities from the Linq selection? How would I reference this returned class in

Why use AsQueryable() instead of List()?

孤街浪徒 提交于 2019-11-26 09:06:32
问题 I\'m getting into using the Repository Pattern for data access with the Entity Framework and LINQ as the underpinning of implementation of the non-Test Repository. Most samples I see return AsQueryable() when the call returns N records instead of List<T>. What is the advantage of doing this? 回答1: AsQueryable just creates a query, the instructions needed to get a list. You can make futher changes to the query later such as adding new Where clauses that get sent all the way down to the database

How to mock the limitations of EntityFramework&#39;s implementation of IQueryable

孤人 提交于 2019-11-26 08:50:29
问题 I am currently writing unit tests for my repository implementation in an MVC4 application. In order to mock the data context, I started by adopting some ideas from this post, but I have now discovered some limitations that make me question whether it is even possible to properly mock IQueryable . In particular, I have seen some situations where the tests pass but the code fails in production and I have not been able to find any way to mock the behavior that causes this failure. For example,

Differences between IQueryable, List, IEnumerator?

旧巷老猫 提交于 2019-11-26 05:00:02
问题 I am wondering what the difference between IQueryable, List, IEnumerator is and when I should use each one? For instance when using Linq to SQL I would do something like this: public List<User> GetUsers() { return db.User.where(/* some query here */).ToList(); } Now I am wondering if I should be using IQueryable instead. I am unsure of the advantages of using it over the list. 回答1: IQueryable<T> is intended to allow a query provider (for example, an ORM like LINQ to SQL or the Entity

What&#39;s the difference between IQueryable and IEnumerable

落爺英雄遲暮 提交于 2019-11-26 04:58:37
问题 I\'m confused as to the difference. Being fairly new to .Net, I know I can query IEnumerables using the Linq extensions. So what is this IQueryable and how does it differ? See also What is the difference between IQueryable[T] and IEnumerable[T]? that overlaps with this question. 回答1: IEnumerable<T> represents a forward-only cursor of T . .NET 3.5 added extension methods that included the LINQ standard query operators like Where and First , with any operators that require predicates or

How to mock the limitations of EntityFramework&#39;s implementation of IQueryable

*爱你&永不变心* 提交于 2019-11-26 01:20:34
I am currently writing unit tests for my repository implementation in an MVC4 application. In order to mock the data context, I started by adopting some ideas from this post , but I have now discovered some limitations that make me question whether it is even possible to properly mock IQueryable . In particular, I have seen some situations where the tests pass but the code fails in production and I have not been able to find any way to mock the behavior that causes this failure. For example, the following snippet is used to select Post entities that fall within a predefined list of categories:

What is the difference between IQueryable<T> and IEnumerable<T>?

青春壹個敷衍的年華 提交于 2019-11-25 22:48:59
问题 What is the difference between IQueryable<T> and IEnumerable<T> ? See also What\'s the difference between IQueryable and IEnumerable that overlaps with this question. 回答1: First of all, IQueryable<T> extends the IEnumerable<T> interface, so anything you can do with a "plain" IEnumerable<T> , you can also do with an IQueryable<T> . IEnumerable<T> just has a GetEnumerator() method that returns an Enumerator<T> for which you can call its MoveNext() method to iterate through a sequence of T .