本文介绍了列表项不会删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码

列表< PurchaseMain> addList =  new  List< PurchaseMain>(); 
列表< PurchaseMain> poRecive = new 列表< PurchaseMain>();
列表< PurchaseMain> poNewGenerate = new List< PurchaseMain>();
使用(InventoryEntities inventoryEntities = new InventoryEntities())
{
var poResult =(来自 res inventoryEntities.PORecived_Main
选择 new PurchaseMain {RecNo = res.RefNo})。ToList< PurchaseMain> ;(); ;
poRecive = poResult;
var poNewResult =( from res in inventoryEntities.PONewGenerate_Main
选择 new PurchaseMain {RecNo = res.RefNo})。 ToList< PurchaseMain>();
poNewGenerate = poNewResult;
foreach var t in poNewGenerate)
{
poRecive.Add(t);
}
var purchaseResult =( from res in inventoryEntities.Purchase_Main
选择 new PurchaseMain {RecNo = res .RecivedPO})。ToList< PurchaseMain>(); ;
var chklist = poRecive;
foreach var t in purchaseResult)
{
for int counter = 0 ;计数器< poRecive.Count; counter ++)
{
if (t.RecNo == poRecive [counter] .RecNo)
{
chklist.Remove(t);
}
}
// foreach(var rt in poRecive)
// {

// }
}
addList = chklist;
}
return addList;





返回时,它包含相同的值..

解决方案

I have a code

List<PurchaseMain> addList = new List<PurchaseMain>();
           List<PurchaseMain> poRecive = new List<PurchaseMain>();
           List<PurchaseMain> poNewGenerate = new List<PurchaseMain>();
           using (InventoryEntities inventoryEntities = new InventoryEntities())
           {
               var poResult = (from res in inventoryEntities.PORecived_Main
                               select new PurchaseMain { RecNo = res.RefNo }).ToList<PurchaseMain>(); ;
               poRecive = poResult;
               var poNewResult = (from res in inventoryEntities.PONewGenerate_Main
                                  select new PurchaseMain { RecNo = res.RefNo }).ToList<PurchaseMain>();
               poNewGenerate = poNewResult;
               foreach (var t in poNewGenerate)
               {
                   poRecive.Add(t);
               }
               var purchaseResult = (from res in inventoryEntities.Purchase_Main
                                     select new PurchaseMain { RecNo = res.RecivedPO }).ToList<PurchaseMain>(); ;
               var chklist = poRecive;
               foreach (var t in purchaseResult)
               {
                   for (int counter = 0; counter < poRecive.Count; counter++)
                   {
                       if (t.RecNo == poRecive[counter].RecNo)
                       {
                           chklist.Remove(t);
                       }
                   }
                   //foreach (var rt in poRecive)
                   //{

                   //}
               }
               addList = chklist;
           }
           return addList;



when it return, it contain same value..

解决方案


这篇关于列表项不会删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 10:22