我正在尝试通过点击按钮删除在数据网格中从其使用的domaindatasource中选择的项目。
按钮点击的代码是:
private void medItemRemove_Click(object sender, RoutedEventArgs e)
{
if (medicineInventoryDataGrid.SelectedIndex != -1)
{
MedicineInventory M = (MedicineInventory)medicineInventoryDataGrid.SelectedItem;
MedicineInventory toRemove = (from a in ctx.MedicineInventories where (a.MedicineInventoryId == M.MedicineInventoryId) select a).Single();
ctx.MedicineInventories.Remove(toRemove);
}
}
但是点击后,我收到以下错误:
“特定实体不包含在EntitySet中。”
我哪里错了?
答案 0 :(得分:0)
试
MedicineInventory M = (MedicineInventory)medicineInventoryDataGrid.SelectedItem.DataItem;