We are converting some of the code on a current project to use LINQ as opposed to straight SQL but being diligent architects we don’t want to break the signatures of the methods returning the information.
All of these methods were returning a System.Data.DataTable object for consumption by objects/controls. So the solution to this problem would be to perform the LINQ query inside the method without changing the signature and just return a DataTable.
Well, fortunately for us Andres and the LINQ guys made this quiet simple. For this example I am using the Sysobjects table from the master DB
private DataTable void test ()
{
var _objects = from sobject in Sysobjects
select new
{
sobject.Name
}
System.Data.SqlClient.SqlCommand _cmd = (System.Data.SqlClient.SqlCommand) [yourdatacontext].GetComman(_objects);
System.Data.DataTable _tmpTable = new System.Data.DataTable();
System.Data.SqlClient.SqlDataAdapter _adpt = new System.Data.SqlClient.SqlDataAdapter(_cmd);
_adpt.Fill(_tmpTable);
return tmpTable;
}