Questions tagged [iqueryable]

.NET Framework Interface, providing functionality to evaluate queries against a specific data source wherein the type of the data is not specified.

The IQueryable interface is intended for implementation by query providers. It is only supposed to be implemented by providers that also implement IQueryable(Of T). If the provider does not also implement IQueryable(Of T), the standard query operators cannot be used on the provider's data source.

The IQueryable interface inherits the IEnumerable interface so that if it represents a query, the results of that query can be enumerated. Enumeration causes the expression tree associated with an IQueryable object to be executed. The definition of "executing an expression tree" is specific to a query provider. For example, it may involve translating the expression tree to an appropriate query language for the underlying data source. Queries that do not return enumerable results are executed when the Execute method is called.

http://msdn.microsoft.com/en-us/library/system.linq.iqueryable.aspx

1457 questions
14
votes
2 answers

IQueryable filtering by a list of IDs

Let's say we have an IQueryable. the Where clause can filter by single ID values, but how can I return an IQueryable based on a list of IDs? [TestMethod] public void TestIQueryableWithList() { int ID1 = 1; List IDs = new List {…
JGilmartin
  • 8,683
  • 14
  • 66
  • 85
14
votes
2 answers

Design Patterns using IQueryable

With the introduction of .NET 3.5 and the IQueryable interface, new patterns will emerge. While I have seen a number of implementations of the Specification pattern, I have not seen many other patterns using this technology. Rob Conery's…
Brad Leach
  • 16,857
  • 17
  • 72
  • 88
13
votes
3 answers

Convert Dataset to IQueryable or IEnumerable

Since there is no Linq to DB2 yet (c'mon IBM!), and I want to deal with IQueryables or IEnumerables in my code, how would I convert a DataTable to an IQueryable? Or an IEnumerable? I have an interface and a class that matches the columns in the…
jlembke
  • 13,217
  • 11
  • 42
  • 56
13
votes
2 answers

In which cases do I need to create two different extension methods for IEnumerable and IQueryable?

Let's say I need an extension method which selects only required properties from different sources. The source could be the database or in-memory collection. So I have defined such extension method: public IQueryable
Farhad Jabiyev
  • 26,014
  • 8
  • 72
  • 98
13
votes
3 answers

IQueryable<> from stored procedure (entity framework)

I want to get IQueryable<> result when executing stored procedure. Here is piece of code that works fine: IQueryable someEntities; var globbalyFilteredSomeEntities = from se in m_Entities.SomeEntitiy where …
13
votes
3 answers

Using EF and WebAPI, how can I return a ViewModel AND support IQueryable/OData?

I've got an ASP.NET WebAPI project. I've recently created EntityFramework entities for all my data tables. But I don't want to expose my data layer & schema to my users. How can I map my entities to a ViewModel (automapper?) and provide IQueryable…
Eric Falsken
  • 4,796
  • 3
  • 28
  • 46
13
votes
2 answers

How to convert an IQueryable to a List?

Just learning LINQ and i've come to a newbie roadblock in my test project. Can you explain what i'm doing wrong? public List retrieveLists(int UserID) { //Integrate userid specification later - need to add listUser table…
Prabu
  • 4,097
  • 5
  • 45
  • 66
13
votes
6 answers

Remove OrderBy from an IQueryable

I have a paging API that returns rows a user requests, but only so many at one time, not the entire collection. The API works as designed, but I do have to calculate the total number of records that are available (for proper page calculations). …
TravisWhidden
  • 2,142
  • 1
  • 19
  • 43
12
votes
6 answers

Parse string into a LINQ query

What method would be considered best practice for parsing a LINQ string into a query? Or in other words, what approach makes the most sense to convert: string query = @"from element in source where element.Property = ""param"" …
smartcaveman
  • 41,281
  • 29
  • 127
  • 212
12
votes
6 answers

Expose IQueryable Over WCF Service

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…
Trust
  • 225
  • 1
  • 4
  • 11
12
votes
5 answers

Combine Expressions instead of using multiple queries in Entity Framework

I have following generic queryable (which may already have selections applied): IQueryable queryable = DBSet.AsQueryable(); Then there is the Provider class that looks like this: public class Provider { public…
Sebastian Krogull
  • 1,468
  • 1
  • 15
  • 31
12
votes
3 answers

Enumerable.Empty().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code

I am getting runtime error This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code. Description: An unhandled exception occurred during the execution of the current web request. Please…
Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265
12
votes
2 answers

How to invoke Expression> against a collection

I have an interface that defines a repository from the Repository pattern: interface IRepository { List GetAllCustomers(Expression> expression); } I've implemented it against Entity Framework: class…
mason
  • 31,774
  • 10
  • 77
  • 121
12
votes
1 answer

Access DataContext behind IQueryable

Is it possible to access the DataContext object behind an IQueryable? If so, how?
Alex
  • 75,813
  • 86
  • 255
  • 348
12
votes
1 answer

Should repositories expose IQueryable to service layer or perform filtering in the implementation?

I'm trying to decide on the best pattern for data access in my MVC application. Currently, having followed the MVC storefront series, I am using repositories, exposing IQueryable to a service layer, which then applies filters. Initially I have been…
matt
  • 219
  • 5
  • 11