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
you don't need to use the MVC extensions or LINQ in order to bind a simple client-side grid (pure client side, no .NET Code) to an SQL backend. you just need to create a REST service which returns the results from the SQL query in JSON arrays, and set the dataSource of the grid to the URL of your service. you can find various tutorials on the web which show how to create REST web services with either .NET or some other backend (such as PHP). You can use a SqlDataAdapter to fill a DataSet from your query and then build a list of business objects (plain class with properties corresponding to the columns). then the resulting list will be automatically serialized by the service. - in case you're using a WCF service, for instance.
DataSet ds = new DataSet(); using (SqlDataAdapter da = new SqlDataAdapter(sqlCmd)) { da.Fill(ds, "Products"); }
Hope it helps. Thanks,
Angel
By this way, we lost the server-side pagging,sorting... right?
You can read the feature parameters from the URL such as pageIndex and pageSize, and build your own query logic depending on your backend. In SQL this will translate to setting TOP/LIMIT clauses, ORDER BY, etc.
With the MVC Wrappers you get this done for you, yes.
Thanks,