我正在使用 Linq,并且有一个如下所示的函数来从数据库中获取数据,因为当我将这些数据拉入网格视图时,我不能 TblSpareParts 表的对象来编辑网格中的数据
private void LoadParts()
{
RST_DBDataContext conn = new RST_DBDataContext();
var AllParts = (from s in conn.TblSpareParts
join m in conn.TblBikeModels on s.ModelID equals m.ModelID
select new { s.SPartName, s.SPartCode, s.SPartLocation, s.SPartID, s.TblBikeModel.ModelName }).ToArray();
SParts_grid.ItemsSource = AllParts;
}
我想要这样的功能,
private void LoadParts()
{
RST_DBDataContext conn = new RST_DBDataContext();
List<TblSparePart> AllParts = (from s in conn.TblSpareParts
join m in conn.TblBikeModels on s.ModelID equals m.ModelID
select new { s.SPartName, s.SPartCode, s.SPartLocation, s.SPartID, s.TblBikeModel.ModelName }).ToList();
SParts_grid.ItemsSource = AllParts;
}
所以基本上我想把这部分var AllParts
改成List<TblSparePart> AllParts
.ToArray();
.ToList();