Do you have any way to bind a sql to Ig grid?
Hello spark_li,
Can you please clarify the scenario that you are trying to implement?
At this moment the best and only way is to point the DataSource to an instance of an IQueryable object
http://help.infragistics.com/Help/NetAdvantage/jQuery/2012.1/CLR4.0/html/igGrid_Developing_ASP_NET_MVC_Applications_with_igGrid.html
Hope hearing from you.
I know ig grid needs a IQueryable object.
I know you apend the paging function in GridDataSourceAction aginst Linq.
GridDataSourceAction aginst Linq.
My question is that I only have some sql now. How can I convert these SQL to an IQueryable object, and I don't want to lost the delay query feature.
For example. I have "Select * from Issues''. Issues table has a lot of rows, So I need the paging feature.
following is the code I want:
[GridDataSourceAction] [ActionName("PagingGetData")] public ActionResult PagingGetData() { var ds= ConverSqlToQuerable(" I have "Select * from Issues'"); //Here, I don't want query data from DB. //I have a lot of Rows in DB. So I need deley DB query // until GridDataSourceAction appends the // paging filter at the tail of my sql. return View("RowSelection", ds); }
[GridDataSourceAction] [ActionName("PagingGetData")] public ActionResult PagingGetData() { var ds= ConverSqlToQuerable("
"PagingGetData"
public
var
"); //Here, I don't want query data from DB. //I have a lot of Rows in DB. So I need deley DB query // until
GridDataSourceAction
appends the // paging filter at the tail of my sql. return View("RowSelection", ds); }
return
"RowSelection"
My question looks like an Linq question more. But I'm hoping get some suggestion from your guys.
Thank you!.
Hi Spark,You are actually asking a very reasonable, but alas, tough question.Yes, it comes down to converting a SQL query to an IQueryable (LINQ expression tree), which isn't a trivial task at all :(
(as indicated here: http://stackoverflow.com/questions/891682/convert-sql-query-back-to-linq-expression-programmatically)
I've struggled with it in the past, but decided that I'd better generate an Entity Framework model and then use LINQ 2 Entities.However, while looking for an alternative, I came across this thread on the MSDN forums:http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/8900f2d2-5833-40af-b867-999cd39f0393/ Take a look at the last post from the DevArt team:Devart LINQ to SQL implementation contains the Query method constructing IQueryable from the SQL query.
public IQueryable<TResult> Query<TResult>(string query, object parameter1, object parameter2);
How, he hasn't given a link to a sample on their website, but I guess he's referring to the LINQConnect product.You can take a look at it if you wish - hope it's of any help to you.Best Regards,Borislav
hi Borislav
Thank you! I have tried Devart LINQ to SQL. It's exact what I want.
I have following codes.
IQueryable<Currency> currencies = context.Query<Currency>("select * from Currencies");currencies = currencies.Where<Currency>(c => c.CurrencyISOCode.Equals("1"));var list = currencies.ToList<Currency>();
Here is the generated SQL:
(@p0 nvarchar(1))SELECT [t1].CurrencyNumber AS [CurrencyNumber], [t1].CurrencyISOCode AS [CurrencyISOCode] FROM ( select * from Currencies ) [t1] WHERE [t1].CurrencyISOCode = @p0
No prob - glad you liked the solution :)And thanks for sharing the code needed in order to get it going.Let me just beautify it for anyone reading this thread:
which translates to: (@p0 nvarchar(1)) SELECT [t1].CurrencyNumber AS [CurrencyNumber],
[t1].CurrencyISOCode AS [CurrencyISOCode] FROM ( select * from Currencies ) [t1] WHERE [t1].CurrencyISOCode = @p0