Databases Reference
In-Depth Information
As you can see, implementation of the
UnleashedMetaModel
class is simple. Its constructor
replaces the built-in
FilterFactory
with a new instance of the
UnleashedFilterFactory
class, and the
CreateTable
method is overridden to return a new instance of the
UnleashedMetaTable
instead of the built-in
MetaTable
. This ensures that all objects in the
Tables
collection are of the type
UnleashedMetaModel
. All that is left to do is modify the
Global.asax
file of the web application to use the
UnleashedMetaModel
instead of the
built-in
MetaModel
, as shown in Listing 13.4.
LISTING 13.4
Modifying Global.asax.cs to Use UnleashedMetaModel
using System;
using System.Web.DynamicData;
using System.Web.Routing;
using DataModel;
namespace WebApplication
{
public class Global : System.Web.HttpApplication
{
public static UnleashedMetaModel DefaultModel = new UnleashedMetaModel();
void Application_Start(object sender, EventArgs e)
{
var modelConfiguration = new ContextConfiguration{ ScaffoldAllTables = true };
DefaultModel.RegisterContext(typeof(NorthwindEntities), modelConfiguration);
RouteTable.Routes.Add(new DynamicDataRoute(“{table}/{action}.aspx”));
}
}
}
Figure 13.3 shows how the Product list page looks with the extended filter lookup algo-
rithm. Comparing it with the original version back in Figure 13.2, you can see that it now
has filter controls for textual and numeric properties, such as the
ProductName
and
UnitsInStock
. These controls were generated by the Text filter template, which was devel-
oped in Chapter 5. Although its immediate capabilities are limited to simple equality
checks, thanks to the fallback-based algorithm, the dynamic pages can automatically take
advantage of the new filter templates as you implement them, without requiring addi-
tional changes in the page template itself.