Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating empty IQueryable list [duplicate]

I want to create a list of empty IQueryable and change it to ToPagedList, I tried the following code :-

IQueryable<VirtualMachine> vm2 = new IQueryable<VirtualMachine>();
vm2.ToPagedList(page, pagesize);

but it will raise the following exception:-

Error 3 A new expression requires (), [], or {} after type

like image 493
John John Avatar asked Nov 19 '13 11:11

John John


People also ask

How do I create an empty list in Java?

Alternatively, you can create an empty list with the type constructor list (), which creates a new list object. If no argument is given, the constructor creates a new empty list, [].

How to convert an IQueryable to a list?

The List class’s constructor can convert an IQueryable for you: public static List<TResult> ToList<TResult>(this IQueryable source) { return new List<TResult>(source); } or you can just convert it without the extension method, of course: var list = new List<T>(queryable); Reply↓ userNovember 30, -0001 at 12:00 am Then just Select:

What is IQueryable<T> in object object set?

Object Set<TEntity> More… The IQueryable<T> interface is intended for implementation by query providers. This interface inherits the IEnumerable<T> interface so that if it represents a query, the results of that query can be enumerated.

How do I get the maximum value of a generic IQueryable?

Returns the maximum value in a generic IQueryable<T>. Invokes a projection function on each element of a generic IQueryable<T> and returns the maximum resulting value. Returns the maximum value in a generic IQueryable<T> according to a specified key selector function.


Video Answer


2 Answers

You could use something like this

 IQueryable<VirtualMachine> vm2 = new VirtualMachine[] {}.AsQueryable();

Do you actually want / need this though? as on MSDN, the IQueryable interface is for use on data sources.

Provides functionality to evaluate queries against a specific data source wherein the type of the data is known.

I would decide whether or not you actually need this before implementing it like this.

like image 71
Joe Avatar answered Sep 23 '22 14:09

Joe


You can't create an instance of an interface - there's no implementation

like image 21
Dave Avatar answered Sep 20 '22 14:09

Dave