public void Init() { Console.WriteLine("启动Filter2.Init"); using (SqlSugarClient db = SugarDaoFilter.GetInstance())//开启数据库连接 { //设置走哪个过滤器 db.CurrentFilterKey = "role1"; //queryable var list = db.Queryable <Student>().ToJson(); //where id=1 , 可以查看id和name //设置走哪个过滤器 db.CurrentFilterKey = "role2"; //queryable var list2 = db.Queryable <Student>().ToJson(); //where id=2 , 可以查看name } }
public void Init() { Console.WriteLine("启动Filter.Init"); using (SqlSugarClient db = SugarDaoFilter.GetInstance())//开启数据库连接 { //设置走哪个过滤器 db.CurrentFilterKey = "role"; //queryable var list = db.Queryable <Student>().ToList(); //通过全局过滤器对需要权限验证的数据进行过滤 //相当于db.Queryable<Student>().Where("id=@id",new{id=1}) //sqlable var list2 = db.Sqlable().From <Student>("s").SelectToList <Student>("*"); //同上 //sqlQuery var list3 = db.SqlQuery <Student>("select * from Student WHERE 1=1"); //同上 } }