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…Read More »

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");
10.// EF does not support table-valued parameters, so we'll do it ourselves
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())
16.    cmd.CommandText = "SomeRealyCoolStoredProcedure";
17.    cmd.CommandType = CommandType.StoredProcedure;
19.    cmd.Parameters.AddWithValue("ID", 123456);
20.    cmd.Parameters.AddWithValue("ValuesTable", dt).TypeName = "MyTableType";
22.    cn.Open();
23.    cmd.ExecuteNonQuery();