private void _btn扫描品种_Click(object sender, RoutedEventArgs e) { using (StatementContext statement = new StatementContext(typeof(Commodity), typeof(CommoditySummarization))) { List <Commodity> commodityList = new List <Commodity>(); var commoditys = statement.Commoditys; var css = statement.CommoditySummarizations; int count = 0; foreach (var cs in css) { if (commoditys.FirstOrDefault(m => m.Code.Equals(cs.Commodity)) == null && commodityList.FirstOrDefault(m => m.Code.Equals(cs.Commodity)) == null) { Commodity cd = new Commodity(); cd.Code = cs.Commodity; cd.Name = cs.Commodity; commodityList.Add(cd); count++; } } statement.AddCommoditys(commodityList); this._listBox品种列表.ItemsSource = null; this._listBox品种列表.ItemsSource = new StatementContext(typeof(Commodity)).Commoditys.ToList(); MessageBox.Show(string.Concat("扫描完成!新增", count, "个品种。")); } }