Linq中几个扩展方法的使用

一个List 保存是ClassOrganization 的实体的信息

依据某个ClassOrganization实体的ID在List中查找该实体,如:

ClassOrganization org = orgList.Find(o=>o.Orgid==orgId);

 

依据某个ClassOrganization实体的ID判断List中是否有该实体,如:

orgList.Exists(o => o.Orgid == OrgID)

 

//IList

 IList<Vanceinfo.Vsg.SystemAdmin.Entity.SmRole> roleList = BusinessCommon.Instance.GetUserRole(userCode, out userId);

int count = roleList.Count<Vanceinfo.Vsg.SystemAdmin.Entity.SmRole>(r => r.RoleName == "公告管理"); //得到在列表中指定条件的角色数量

 if(count>0)

{

  //证明有该记录

}

 

 

查找IList中的某个实体

IList<BudgetData> list = bll.GetListByCondition(type, iBugetType);

if (!string.IsNullOrEmpty(strYear))
                {
                    strYearMonth = strYear + "-" + strMonth;

                    obj = list.SingleOrDefault<BudgetData>(b => b.YearMonth == strYearMonth && b.DepartCode == strDepart);
                }

 

posted @ 2010-06-24 18:29  Vihone  阅读(198)  评论(0编辑  收藏  举报