linq依據傳入數據集合查詢相應子級數據
阿新 • • 發佈:2017-07-31
ndt ng- source dsm 所有 repeat 點數據 sharp one
工作中經經常使用到的linq依據傳入數據集合查詢相應子級數據,整理共享,希望大家都能用得上,代碼中doublesArray 為父節點相應ID數據集合,再依據ID數據集合查詢所有子級數據。
//獲取緩存數據 object obj = Caching.GetCache(CacheKey + UModel.RoleId); if (obj != null)//判讀緩存數據是否null { SysFunList = (DataSet)obj; } else { string strSql = "select * from View_SysRoleList where LoginID='" + UModel.LoginId + "' order by [Custom_Displayorder]"; SysFunList = SqlHelper.Query(SqlHelper.LocalSqlServer, strSql.ToString()); Caching.SetCache(CacheKey + UModel.RoleId, SysFunList); } //linq獲取數據集內全部父節點數據 var query = (from t in SysFunList.Tables[0].AsEnumerable() where t.Field<int>("Custom_ParentNodeId") == 0 select t); if (query.Count() > 0) { //linq獲取數據內全部父節點相應ID var doublesArray = query.Select(one => one.Field<int>("Custom_NodeId")); if (doublesArray.Count() > 0) { //linq 依據ID數據結合獲取相應下一級數據 var foos = from tq in SysFunList.Tables[0].AsEnumerable() where doublesArray.Contains(tq.Field<int>("Custom_ParentNodeId")) orderby tq.Field<int>("Custom_Displayorder") descending select tq; //轉換為DataTable DataTable boundTable = foos.CopyToDataTable<DataRow>(); RepeaterMeau.DataSource = boundTable; RepeaterMeau.DataBind(); } }
linq依據傳入數據集合查詢相應子級數據