1
var flowers = from f in c.Product
select new
{
f.ProductID,
f.Price,
f.Name,
f.Description
};
List<int> IDsToRemove = new List<int>();
foreach(var newRow in flowers)
{
if (((List<int>)Session["UsedIDs"]).Contains(newRow.ProductID))
{
IDsToRemove.Add(newRow.ProductID);
}
}
我已經得到了ID的,我想刪除那裏是usedIDs並從查詢中productIDs之間的匹配刪除項目,所以我把所有的匹配到整數IDToRemove的列表。現在我不知道該怎麼做:如何從IQueryable的匿名類型
foreach(var id in IDsToRemove){
flowers.remove(id) }
ddlFlowers.DataSource = flowers.ToList();
刪除項目的相反,你可以do'ddlFlowers.DataSource = flowers.Except(IDS ();' – shahkalpesh
@caleb我編輯了我的答案 –
或者,'flowers.RemoveAll(f => ids.Contains(f));'將移除這些項目。 – shahkalpesh