The solution I am proposing may not be exactly what you are looking for, but I think it will help you figuring out what you need. One way I have done sth similar is by creating a DA library and using that in C# Interactive Window
. Below is the sample:
I would have a class library project, MyProject.MyDA:
namespace MyDa
{
public class CustomerDa
{
public DataTable LoadData(string sqlCommandText = "")
{
//do your try catch finally and all the good stuff
var connString = @"Data Source=ServerName;Initial Catalog=AdventureWorks2014;Integrated Security=SSPI;";
var conn = new SqlConnection(connString);
SqlDataReader dataReader;
//you could accept the command text as a parameter
string sql = "select top 10 * FROM [AdventureWorks2014].[HumanResources].[Department]";
var result = new DataTable("Department");
conn.Open();
SqlCommand command = new SqlCommand(sql, conn);
dataReader = command.ExecuteReader();
result.Load(dataReader);
dataReader.Close();
command.Dispose();
conn.Close();
//instead of a datatable, return your object
return result;
}
}
}
Build your DA project, now in C# Interactive
, you would do sth like:
> #r "D:\blah\Blah\MyDa\bin\Debug\MyDa.dll"
> using MyDa;
> var a = new CustomerDa();
> var r = a.LoadData();
> r.Rows[0]
DataRow { HasErrors=false, ItemArray=object[4] { 1, "Engineering", "Research and Development", [4/30/2008 12:00:00 AM] }, RowError="", RowState=Unchanged, Table=[] }
> r.Rows.Count //you can do all the good LINQ stuff now on the result
10
You can do it this way, but I feel this flow requires more work and ceremony than I would like and is still imperfect. Anyways, that's one way to accomplish what you are looking for. I would also recommend using LinqPad
if you prefer to query using LINQ
.