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
51
votes
4 answers

What instantiate-able types implementing IQueryable are available in .Net 4.0?

Within the context of C# on .Net 4.0, are there any built-in objects that implement IQueryable?
one.beat.consumer
  • 9,414
  • 11
  • 55
  • 98
44
votes
6 answers

The provider for the source IQueryable doesn't implement IAsyncQueryProvider

I have some codes like below, I want to write unit tests my method. But I'm stuck in async methods. Can you help me please ? public class Panel { public int Id { get; set; } [Required] public double Latitude { get; set; } public double…
41
votes
4 answers

How do I mock IQueryable

I am creating a repository that exposes IQueryable. What is the best way to mock this out for my unit testing? Since I am using RhinoMocks for the rest of my mock objects, I tried to do the following: IQueryable QueryObject = …
Aaron Weiker
  • 2,523
  • 2
  • 21
  • 22
38
votes
4 answers

Should I return IEnumerable or IQueryable from my DAL?

I know this could be opinion, but I'm looking for best practices. As I understand, IQueryable implements IEnumerable, so in my DAL, I currently have method signatures like the following: IEnumerable GetProducts(); IEnumerable
Armstrongest
  • 15,181
  • 13
  • 67
  • 106
37
votes
8 answers

How do I add a new record to an IQueryable variable?

The IQueryable results is queried from my db using LINQ, How do I add a new record to the IQueryable result.
silent200
36
votes
6 answers

Cannot implicitly convert type 'System.Linq.IQueryable' to 'int?'

var cityList = from country in doc.Element("result") .Element("cities") .Descendants("city") select new { Name = country.Element("name").Value, Code =…
Aneef
  • 3,641
  • 10
  • 43
  • 67
36
votes
4 answers

Automatically Compile Linq Queries

We've found that compiling our Linq queries is much, much faster than them having to compile each time, so we would like to start using compiled queries. The problem is that it makes code harder to read, because the actual syntax of the query is off…
tghw
  • 25,208
  • 13
  • 70
  • 96
34
votes
4 answers

IQueryable order by two or more properties

I am currently ordering a list of custom objects using the IQueryable OrderBy method as follows: mylist.AsQueryable().OrderBy("PropertyName"); Now I am looking to sort by more than one property. Is there any way to do that? Thanks, Yannis
Yannis
  • 6,047
  • 5
  • 43
  • 62
33
votes
4 answers

Repository Methods vs. Extending IQueryable

I have repositories (e.g. ContactRepository, UserRepository and so forth) which encapsulate data access to the domain model. When I was looking at searching for data, e.g. finding a contact whose first name starts with XYZ a contact whose…
Alex
  • 75,813
  • 86
  • 255
  • 348
31
votes
7 answers

Determine whether an IQueryable has been ordered or not

Is there a way to know if an IQueryable has been ordered (using OrderBy or OrderbyDescending)? So I know whether to call OrderBy or ThenBy on the collection. IQueryable contacts = Database.GetContacts(); I tried contacts is…
Bertrand Marron
  • 21,501
  • 8
  • 58
  • 94
30
votes
4 answers

.NET Entity Framework - IEnumerable VS. IQueryable

Please see this line of code. This is an invocation of a stored procedure, which returns an ObjectResult. In order to extract the long values I added the Select: dbContext.FindCoursesWithKeywords(keywords).Select(l => l.Value); Based on…
justabuzz
  • 842
  • 1
  • 9
  • 19
30
votes
2 answers

How to mock the limitations of EntityFramework's implementation of IQueryable

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…
Tim Coulter
  • 8,705
  • 11
  • 64
  • 95
27
votes
8 answers

IQueryable OfType where T is a runtime Type

I need to be able to get something similar to the following to work: Type type = ??? // something decided at runtime with .GetType or typeof; object[] entityList = context.Resources.OfType().ToList(); Is this possible? I am able to use .NET 4…
asleep
  • 4,054
  • 10
  • 34
  • 51
26
votes
2 answers

List to implement IQueryable

I'm trying to create a mock for my IRepository interface: public interface IRepository : ICollection, IQueryable { } With this implementation: public class RepositoryFake : List, IRepository { public Expression Expression …
Sly
  • 15,046
  • 12
  • 60
  • 89
26
votes
3 answers

How to get the count from IQueryable

I am implementing paging in my GridView. From this article, I need two methods: public IQueryable BindEmployees(int startRowIndex, int maximumRows) { EmployeeInfoDataContext dbEmp = new EmployeeInfoDataContext(); var query = from emp in…
Homam
  • 23,263
  • 32
  • 111
  • 187
1
2
3
97 98