I get an error when I attempt to use the server-side filtering, as described in your demo at http://demos.telerik.com/silverlight/#GridView/DomainDataSource .
The problem is that I can't filter the gridview using navigation properties, and almost all the properties in my gridview are navigation properties. I am able to bind the navigation properties in my grid, but when I click on the gridview's filter icon to filter by distinct values, I get an error "ArgumentException was unhandled by user code. 'Location.LocationName' is not a member of type 'MyApplication.Web.Models.Order'.
Is it possible to rewrite the expression to navigate thru the navigation property?
Here's my slightly modified version of your demo code that retrieves the distinct values. It still fails even after adding the "Includes". The error occurs on the evaluation of propertyName in the last line of CreateSelectorExpression.
public
List<DistinctValue> GetDistinctValues(
string
propertyName)
{
var list =
new
List<DistinctValue>();
var values =
this
.ObjectContext.Orders
.Include(
"Item"
)
.Include(
"Location"
)
.Include(
"Source"
)
.Select(CreateSelectorExpression(propertyName)).Distinct();
int
i = 0;
foreach
(var value
in
values)
{
list.Add(
new
DistinctValue() { ID = i, Value = value });
i++;
}
return
list;
}
private
static
Expression<Func<ItemLocationSource,
string
>> CreateSelectorExpression(
string
propertyName)
{
var paramterExpression = Expression.Parameter(
typeof
(Order));
return
(Expression<Func<Order,
string
>>)Expression.Lambda(Expression.PropertyOrField(paramterExpression, propertyName), paramterExpression);
}
Here's a snippet of the relevant client-side code in case you need it.
<
domainSvcs:DomainDataSource
x:Name
=
"OrdersDataSource"
AutoLoad
=
"True"
QueryName
=
"GetOrders"
PageSize
=
"25"
FilterOperator
=
"Or"
>
<
domainSvcs:DomainDataSource.DomainContext
>
<
MyDomainContextWeb:MyDomainContextDomainContext
/>
</
domainSvcs:DomainDataSource.DomainContext
>
</
domainSvcs:DomainDataSource
>
<
telerikGridView:RadGridView
x:Name
=
"gridOrders"
CanUserReorderColumns
=
"True"
CanUserSortColumns
=
"True"
ItemsSource
=
"{Binding Data, ElementName=OrdersDataSource}"
AutoGenerateColumns
=
"False"
IsBusy
=
"{Binding IsBusy, ElementName=OrdersDataSource}"
AutoExpandGroups
=
"True"
Filtering
=
"gridOrders_Filtering"
DistinctValuesLoading
=
"gridOrders_DistinctValuesLoading"
ScrollViewer.VerticalScrollBarVisibility
=
"Visible"
AlternationCount
=
"2"
RowIndicatorVisibility
=
"Collapsed"
RowActivated
=
"gridOrders_RowActivated"
AlternateRowBackground
=
"{StaticResource AlternateBGBrush}"
GridLinesVisibility
=
"Vertical"
CanUserInsertRows
=
"False"
shared:GridViewColumnPicker.IsEnabled
=
"True"
CanUserDeleteRows
=
"False"
IsReadOnly
=
"True"
>
<
telerikGridView:RadGridView.Columns
>
<
telerikGridView:GridViewDataColumn
Header
=
"{Binding Path=ApplicationStrings.ItemID, Source={StaticResource ResourceWrapper}}"
DataMemberBinding
=
"{Binding Item.ItemID}"
TextAlignment
=
"Right"
HeaderTextAlignment
=
"Center"
/>
<
telerikGridView:GridViewDataColumn
Header
=
"{Binding Path=ApplicationStrings.ItemName, Source={StaticResource ResourceWrapper}}"
DataMemberBinding
=
"{Binding Item.ItemName}"
TextAlignment
=
"Right"
HeaderTextAlignment
=
"Center"
/>
<
telerikGridView:GridViewDataColumn
Header
=
"{Binding Path=ApplicationStrings.LocationID, Source={StaticResource ResourceWrapper}}"
DataMemberBinding
=
"{Binding Location.LocationID}"
TextAlignment
=
"Right"
HeaderTextAlignment
=
"Center"
/>
<
telerikGridView:GridViewDataColumn
Header
=
"{Binding Path=ApplicationStrings.LocationName, Source={StaticResource ResourceWrapper}}"
DataMemberBinding
=
"{Binding Location.LocationName}"
TextAlignment
=
"Right"
HeaderTextAlignment
=
"Center"
/>
<
telerikGridView:GridViewDataColumn
Header
=
"{Binding Path=ApplicationStrings.SourceID, Source={StaticResource ResourceWrapper}}"
DataMemberBinding
=
"{Binding Source.SourceID}"
TextAlignment
=
"Right"
HeaderTextAlignment
=
"Center"
/>
<
telerikGridView:GridViewDataColumn
Header
=
"{Binding Path=ApplicationStrings.SourceName, Source={StaticResource ResourceWrapper}}"
DataMemberBinding
=
"{Binding Source.SourceName}"
TextAlignment
=
"Right"
HeaderTextAlignment
=
"Center"
/>
</
telerikGridView:RadGridView.Columns
>
</
telerikGridView:RadGridView
>
<
telerikData:RadDataPager
x:Name
=
"RadDataPager1"
Source
=
"{Binding Data, ElementName=OrdersDataSource}"
DisplayMode
=
"FirstLastPreviousNextNumeric"
IsTotalItemCountFixed
=
"True"
VerticalContentAlignment
=
"Top"
Grid.Row
=
"1"
/>