user1404577
user1404577

Reputation:

Creating empty IQueryable list

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

Upvotes: 7

Views: 10030

Answers (3)

Joe
Joe

Reputation: 7311

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.

Upvotes: 14

Dave
Dave

Reputation: 3621

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

Upvotes: 2

David Pilkington
David Pilkington

Reputation: 13628

You are trying to create an instance of an interface not an object. THis cannot be done.

Have a look at this SO question

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

Paying special attention to this

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.

Upvotes: 1

Related Questions