Databases Reference
In-Depth Information
done in the UnleashedMetaTable class in the Unleashed.DynamicData project of the
sample solution accompanying this topic:
public partial class UnleashedMetaTable : MetaTable
{
private readonly CustomQueryAttribute customQueryAttribute;
public UnleashedMetaTable(
UnleashedMetaModel model, TableProvider provider)
: base(model, provider)
{
this.customQueryAttribute = this.Attributes
.OfType<CustomQueryAttribute>()
.FirstOrDefault();
// ...
}
public IQueryable GetQueryable(IQueryable query)
{
if (this.customQueryAttribute != null)
query = this.customQueryAttribute.GetQueryable(query);
return query;
}
public override IQueryable GetQuery(object context)
{
IQueryable baseQuery = base.GetQuery(context);
IQueryable customQuery = this.GetQueryable(baseQuery);
return customQuery;
}
}
The overridden GetQuery method is the same as you left it in the discussion of imple-
menting row-level security with the metadata API earlier in this chapter. However, the
constructor now tries to find the CustomQueryAttribute that might have been applied to
the entity class this meta table object represents and stores it in the read-only
customQueryAttribute field. The GetQueryable method of the UnleashedMetaTable uses
this field to call the method specified in the attribute (if any) and replaces the original
query with the object it returns.
NOTE
The new implementation of the GetQueryable method is significantly shorter than the
following version created earlier, which hard-coded the query logic directly:
public IQueryable GetQueryable (IQueryable query)
{
IPrincipal user = HttpContext.Current.User;
 
Search WWH ::




Custom Search