Databases Reference
In-Depth Information
The overridden
GetFilteredColumns
method calls the
GetScaffoldColumns
method of the
MetaTable
to get a list of all properties that can be displayed in a list page in read-only mode.
In other words, only columns already displayed in a dynamic
GridView
control are candi-
dates for filtering. This eliminates some low-level properties, such as the generated primary
keys and primitive components of foreign keys that are not displayed in list pages by default.
From the end-user perspective, it would be strange to see an option to filter a Product page
by the ProductID or the SupplierID columns, which are not displayed in the grid.
The initial list of properties returned by the
GetScaffoldColumns
method is further
reduced by calling the
IsFilterable
method and leaving only those
MetaColumn
objects
for which it returns
true
. This method mimics the rules used by the
GetScaffoldColumns
method itself, only as they apply to filtering of property values, not their display. For
instance, if the property has a
FilterUIHintAttribute
applied to it, assume that it is
filterable. Likewise, if the property has a
DisplayAttribute
applied with an explicitly spec-
ified
AutoGenerateFilter
value, this value determines whether the property is considered
filterable (
true
or
false
). All other types of properties, with the exception of custom prop-
erties and “children” navigation properties, are considered filterable by default.
Extending the MetaModel Class
The
MetaModel
class serves as a root object for accessing the metadata information in
Dynamic Data web applications. Its default implementation creates and exposes the built-
in
FilterFactory
and
MetaTable
classes. The
UnleashedMetaModel
extends the built-in
class to create the
UnleashedFilterFactory
and
UnleashedMetaTable
instances instead.
Listing 13.3 shows a complete implementation of the new class.
LISTING 13.3
Unleashed.DynamicData\UnleashedMetaModel.cs
using System;
using System.Web.DynamicData;
using System.Web.DynamicData.ModelProviders;
namespace Unleashed.DynamicData
{
public class UnleashedMetaModel : MetaModel
{
public UnleashedMetaModel()
{
this.FilterFactory = new UnleashedFilterFactory(this);
}
protected override MetaTable CreateTable(TableProvider provider)
{
return new UnleashedMetaTable(this, provider);
}
}
}