Helpful JavaScript Methods for the Telerik Grid for ASP.NET MVC

The Telerik MVC Grid is quite a cool component. Nevertheless, some client-side API functions are desperately missing. For example, you cannot select or deselect rows by code. Also, there’s no way to do client-side-filtering (i.e. hide rows based on values withoud re-populating the whole grid). So here is a set of some functions that were helpful to me – suite yourselves… Continue reading

Getting The Database Connection String From an ObjectContext

The trick here is to cast the Connection property of the ObjectContext to the type System.Data.EntityClient.EntityConnection. Then you can access the StoreConnection property:

01.var dataTable = new DataTable
02.    {
03.        Columns = { new DataColumn("Value", typeof(string)) }
04.    };
05.dataTable.Rows.Add("first row");
06.dataTable.Rows.Add("second row");
07.dataTable.Rows.Add("third row");
08. 
09.//
10.// EF does not support table-valued parameters, so we'll do it ourselves
11.//
12.using (var ctx = new MyObjectContext())
13.using (var cn = new SqlConnection(((System.Data.EntityClient.EntityConnection)ctx.Connection).StoreConnection.ConnectionString))
14.using (var cmd = cn.CreateCommand())
15.{
16.    cmd.CommandText = "SomeRealyCoolStoredProcedure";
17.    cmd.CommandType = CommandType.StoredProcedure;
18. 
19.    cmd.Parameters.AddWithValue("ID", 123456);
20.    cmd.Parameters.AddWithValue("ValuesTable", dt).TypeName = "MyTableType";
21. 
22.    cn.Open();
23.    cmd.ExecuteNonQuery();
24.}