Databases Reference
In-Depth Information
LISTING 12.8 Continued
EntityDataSourceSelectingEventArgs e)
{
if (string.IsNullOrEmpty(e.SelectArguments.SortExpression))
{
e.SelectArguments.SortExpression = string.Join(“,”,
this.ForeignKeyColumn.Table.PrimaryKeyColumns.Select(c => c.Name));
}
}
}
}
The Filter_Init method handles the Init event of the nested UnleashedFilter control
and initializes all required properties. In particular, it sets the DataSource property of the
UnleashedFilter control with the DataSource object of the filter template itself. It also
sets the Table property of the nested UnleashedFilter control. Normally, this is not
necessary because the UnleashedFilter automatically uses the MetaTable object associated
with the data source control. However, in this case you want the nested UnleashedFilter
control to be associated with the MetaTable object describing the parent entity. That is
why it is set explicitly, using the ParentTable property of the ForeignKeyColumn object
that represents the foreign key entity property Supplier, with which the filter template is
associated.
NOTE
In the Parent field template, the DataItemContainer provided both the MetaTable and
entity object. In filter templates, which do not rely on data binding to display initial values,
this works differently. Instead of data binding, filter templates rely on the DefaultValue
and DefaultValues properties provided by the QueryableFilterUserControl base
class.
Finally, the Filter_Init method sets the DataField property of the nested UnleashedFilter
control. It does that based on the value of the DisplayField property of the filter template
itself. In this current example, the DisplayField property is specified as a custom attribute
of the UnleashedFilter in page markup, and the control takes care of initializing the
property automatically.
The last task performed by the Filter_Init method is setting up a couple of event
handlers for the data source control. The DataSourceContextCreated method handles the
ContextCreated event. This method saves the ObjectContext , a NorthwindEntities object
in this example, in the dataSourceContext private field of the template. This is important
for the query logic discussed next that relies on the join LINQ operator and requires both
queries to come from the same ObjectContext .
The DataSourceSelecting handles the Selecting event of the EntityDataSource control
to work around some of its limitations. The built-in paging logic in the EntityDataSource
Search WWH ::




Custom Search