现在的位置: 首页 > 综合 > 正文

巧用Contains可以做到过滤同类项!

2012年12月19日 ⁄ 综合 ⁄ 共 709字 ⁄ 字号 评论关闭

如果你想针对某个数组之间的同类项来进行过滤,Contains就能做到。

 如下面这种情况,是筛选出,不包含itemList列表中的值。

  public List<int> FilterTemp_InfoBooth_R(int tempID)
  {
    return base.LoadRepository.GetEntities<Info_BoothTemp_Info_R>().Where(i => i.BoothTempID == tempID).Select(i => i.BoothInfoID).ToList<int>();
  }
public ActionResult AddExitsInfo_InTo_BoothTemp(int? page)
{
    int tempID;
    int.TryParse(Request.QueryString["tempid"], out tempID);
    ViewBag.tempID = tempID;

    List<int> itemList = info_BoothManager.FilterTemp_InfoBooth_R(tempID);
    PredicateList<Info_BoothInfo> predict = new PredicateList<Info_BoothInfo>();
    predict.Add(i => !itemList.Contains(i.BoothInfoID));

    PagingParam pp = new PagingParam(page ?? 1, 15);
    var listModel = info_BoothManager.GetModel_BoothInfo(predict, pp);

    return View(listModel);
}

 

 

抱歉!评论已关闭.