public void init(){
var q=from c in dbs.T_ROLE
select c;
b=q.ToList().AsQueryable();
}
List result= new List ();
List parents= new List ();
IQueryable b;
public void getChilds(int pid)
{
var q = from c in b
where c.T_ROLE_PID == pid
select c;
if (q.Count() > 0)
{
List li = q.ToList();
foreach(db.T_ROLE t in li){
result.Add(t);
getChilds(t.T_ROLE_ID);
}
}
}
public void getParent(int id){
var q = from c in b
where c.T_ROLE_ID == id
select c;
if (q.Count() > 0)
{
List li = q.ToList();
foreach(db.T_ROLE t in li){
result.Add(t);
getChilds(t.T_ROLE_PID);
}
}
}
这里关键语句为 AsQueryable(),这样将数据库表变成内存数据表。从而对其进行任意的操作
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15116811/viewspace-498137/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/15116811/viewspace-498137/