John Mott
John Mott

Reputation: 445

I'm looking for a way to build a IQueryable query from a string

I want to build an IQueryable query from a string (it would come from a table). The reason I want the IQueryable is I want to use OrderBy, Take and Skip to do paging. I'm using Entity Framework with DBContext so I looked at Entity SQL but it looks like its restricting the query to a class.

What I want to do is:

string sql = GetQueryFromDatabase();
IQueryable q = PerformMagicToMakeStringIQueryable(sql);
q = q.OrderBy(somefield).Skip(5).Take(10);

From there I'm good, I know how to find out what fields are in the query and do what I need.

Ideas?

thanks,

john

Upvotes: 0

Views: 540

Answers (1)

mcintyre321
mcintyre321

Reputation: 13306

There's a thing called DynamicLinq which you can use.

There are lots of different versions as MS released the original as source code and it's been modified a gazillion times:

Here's one with docs:

http://dynamiclinq.azurewebsites.net/

Here are the others:

https://www.nuget.org/packages?q=dynamic+linq

Upvotes: 1

Related Questions