我在LINQ查询上得到这个错误,我不确定为什么。当我运行表是空的,但当我添加一个断点,一个力的结果,然后它的工作找到并添加所有的数据在完美
private void GetSQLOraclelinqData()
{
var TstarData = GetTrackstarTruckData();
var M5Data = GetM5Data();
DataTable ComTable = new DataTable();
foreach (DataColumn OraColumn in M5Data.Columns)
{
ComTable.Columns.Add(OraColumn.ColumnName, OraColumn.DataType);
}
foreach (DataColumn SQLColumn in TstarData.Columns)
{
if (SQLColumn.ColumnName == "VehicleName")
ComTable.Columns.Add(SQLColumn.ColumnName + 2, SQLColumn.DataType);
else
ComTable.Columns.Add(SQLColumn.ColumnName, SQLColumn.DataType);
}
var results = TstarData.AsEnumerable().Join(M5Data.AsEnumerable(),
a => a.Field<String>("VehicleName"),
b => b.Field<String>("Unit_NO"),
(a, b) =>
{
DataRow row = ComTable.NewRow();
row.ItemArray = a.ItemArray.Concat(b.ItemArray).ToArray();
ComTable.Rows.Add(row);
return row;
});
SQLDataTable.ItemsSource = ComTable.DefaultView;
}
添加列表:
var results = TstarData.AsEnumerable().Join(M5Data.AsEnumerable(),
a => a.Field<String>("VehicleName"),
b => b.Field<String>("Unit_NO"),
(a, b) =>
{
DataRow row = ComTable.NewRow();
row.ItemArray = a.ItemArray.Concat(b.ItemArray).ToArray();
ComTable.Rows.Add(row);
return row;
}).ToList();