我正在尝试弄清楚如何根据角色动态授权我的上下文。
public interface IConstraintResolver
{
Expression<Func<TEntity, bool>>[] GetConstraintsForTypeByRole<TEntity>()
where TEntity : class;
}
public class AuthorizationContext : DbContext
{
protected IConstraintResolver _constraintResolver;
public AuthorizationContext(IConstraintResolver constraintResolver)
{
this._constraintResolver = constraintResolver;
}
public override DbSet<TEntity> Set<TEntity>()
{
var defaultSet = base.Set<TEntity>();
var constraints = this._constraintResolver.GetConstraintsForTypeByRole<TEntity>();
var filteredSet = base.Set<TEntity>().AsQueryable();
foreach(var constraint in constraints)
{
filteredSet = filteredSet.Where(constraint);
}
//how do I apply this back to the innerQueryable
return filteredSet;
}
}
我的问题是,在应用了我的可查询后,如何使其成为Set的默认可查询。
我发现了一个与旧DbSet here
一起使用的陀螺但.Net Core不包含IDBSet
如何创建自定义dbset,或者如何过滤现有dbSet?
答案 0 :(得分:1)
通过global filters提供更好的方法:
webview = (WebView) findViewById(R.id.webview);
webview.loadUrl(url);
contentView = (TextView) findViewById(R.id.contentView);
//Main m=new Main(this);
// m.passData();
new Thread(new Runnable() {
@Override
public void run() {
Document doc = null;
// Element element;
try {
String url = "http://example.com/";
doc = Jsoup.connect(url).get();
e = doc.select("div.container").first().parents();
a = e.toString();
} catch (IOException e) {
e.printStackTrace();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
contentView.setText(a);
}
});
}
}).start();