您好,我尝试将C#中的SQL查询转换为LinqToSql。我的代码是从SQL Server获取2个表,并将它们放在这样的DataSet中:
private void Valid_Cmd_Btn_Click(object sender, RoutedEventArgs e)
{
int numCmd = Convert.ToInt32(NumCmd_TB.Text);
#region ARTICLES
comm = new SqlCommand("SELECT * FROM ARTICLES", conn);
SqlDataAdapter dap = new SqlDataAdapter(comm);
DataTable dt = new DataTable("ARTICLES");
dap.Fill(dt);
#endregion
#region CMD_DET
comm = new SqlCommand("SELECT * FROM CMD_DET", conn);
SqlDataAdapter dap1 = new SqlDataAdapter(comm);
DataTable dt1 = new DataTable("CMD_DET");
dap1.Fill(dt1);
#endregion
#region CMD_ENT
comm = new SqlCommand($"SELECT * FROM CMD_ENT WHERE CMD_ENT_ID= {numCmd}", conn);
SqlDataAdapter dap2 = new SqlDataAdapter(comm);
DataTable dt2 = new DataTable("CMD_ENT");
dap2.Fill(dt2);
#endregion
DataSet ds = new DataSet();
ds.Tables.Add(dt);
ds.Tables.Add(dt1);
ds.Tables.Add(dt2);
}
现在我想对LinqToSql语法做同样的事情:
private void Valid_Cmd_Btn_Click(object sender, RoutedEventArgs e)
{
DataClasses1DataContext dc = new DataClasses1DataContext();
var articles = from a in dc.ARTICLES
select a;
// How to put this in a Datable ?
DataClasses1DataContext dc1 = new DataClasses1DataContext();
var det = from d in dc.CMD_DET
select d;
// How to put this in a Datable ?
//...
// and then like in Sql query how to get those 2 tables in a Dataset ??
}