Databases Reference
In-Depth Information
namespace WebApplication.DynamicData.Filters
{
public partial class ParentFilter : UnleashedFilterTemplate
{
public override IQueryable GetQueryable(IQueryable childQuery)
{
MetaTable parentTable = this.ForeignKeyColumn.ParentTable;
IQueryable emptyQuery = parentTable.GetQuery(this.dataSourceContext);
IQueryable parentQuery = this.filter.FilterTemplate.GetQueryable(emptyQuery);
if (parentQuery != emptyQuery)
{
MetaTable childTable = this.ForeignKeyColumn.Table;
MetaColumn childColumn = childTable.GetColumn(
this.ForeignKeyColumn.ForeignKeyNames[0]);
MetaColumn parentColumn = parentTable.PrimaryKeyColumns[0];
MethodCallExpression joinCall = Expression.Call(
typeof(Queryable),
“Join”,
new Type[] {
childQuery.ElementType,
parentQuery.ElementType,
childColumn.EntityTypeProperty.PropertyType,
childQuery.ElementType
},
new Expression[] {
childQuery.Expression,
parentQuery.Expression,
BuildChildKeySelector(childQuery.ElementType, childColumn.Name),
BuildParentKeySelector(parentQuery.ElementType, parentColumn.Name,
childColumn.EntityTypeProperty.PropertyType),
BuildResultSelector(childQuery.ElementType, parentQuery.ElementType)
});
childQuery = childQuery.Provider.CreateQuery(joinCall);
}
return childQuery;
}
private static LambdaExpression BuildChildKeySelector(
Type entityType, string propertyName)
{
ParameterExpression parameter = Expression.Parameter(entityType, “child”);
MemberExpression property = Expression.Property(parameter, propertyName);
Search WWH ::




Custom Search