1

我有一个GridControl,其中包含带有 Checkbox 控件的项目列表。

我正在添加和删除List<int>包含选中项目列 ID 值的自定义 ID。现在,我想循环List<int>并从 Table 中选择记录,并通过获取这些选中的项目想要使用Linq插入到其他表中使用C#的WPF中的实体。

List<Infill> infillList = new List<Infill>();
List<int> infillListIDs=new List<int>();
private bool ProcessItem(bool IsChecked)
        {
            bool result = false;
            Infill item = grdInfillInner.FocusedRow as Infill;
            if (IsChecked)
            {

                if (item != null)
                {
                    // DO STUFF HERE EXAMPLE ADD or REMOVE Item to a list, BASED on CHECKED or UNCHECKED!!!
                    int infillid = item.InfillID;
                    infillListIDs.Add(infillid);
                    result = true;
                }
            }
            else
            { 
                if(infillListIDs.Contains(item.InfillID))
                {
                    // if uncheked the checked item then remove from custom list
                    infillListIDs.Remove(item.InfillID);

                }
            }
            grdInfillInner.FocusedRowHandle = -1;
            return result;
        }

private void BtnInsert_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Total Items :" + infillListIDs.Count);
            //Insert the record in other table (having same table structure)
            //here by selecting from infillListIDs custom list of type List<int> 

        }
private void CheckEdit_Checked(object sender, RoutedEventArgs e)
        {
            e.Handled = ProcessItem(true);

        }

        private void CheckEdit_Unchecked(object sender, RoutedEventArgs e)
        {
            e.Handled = ProcessItem(false);
        }
protected void GetAllInfills()
        {
            List<Infill> infillList = new List<Infill>();
            infillList=BLL.GetAllInfills();
            if (infillList != null)
            {
                grdInfill.ItemsSource = infillList;
                grdInfill.GroupBy(grdInfill.Columns["Glass.GlassType"], ColumnSortOrder.Ascending);
                grdInfill.GroupBy(grdInfill.Columns["Glass.Glass_Description"], ColumnSortOrder.Ascending);
                grdInfill.AutoExpandAllGroups = true;

            }
        }

我想从infill表中获取记录,其中infillListIDs包含来自Infill表的所有检查行的ID ,并且在单击插入按钮时具有相同结构的表!insert into DummyInfill

4

1 回答 1

0

看到这个:https ://stackoverflow.com/a/15829249/265100

获取具有匹配 ID 的对象并添加到新表中。

Using (DB _db = new DB()){
  foreach(Infill inf in InfillCol){
    DummyInfill.Add(inf);
  }
  DummyInfill.SaveChanges();
}

我不知道您使用的是什么版本的 EF,但我知道您可以实现 SQLBulkCopy。看到这篇文章:https ://stackoverflow.com/a/1610014/265100

于 2013-06-27T15:26:56.793 回答