开发者

Silverlight 4 Domain Data Source Filter Descriptor on nested property

I have an object model where I'm checking a filter value of nested child property e.g.

Order -> Customer

And Customer has a property e.g. Name = "Joe Bloggs"

My domain service returns IQueryable<Order>. My domain data source is bound to this (and in turn my Grid is bound to the domain data source), and I have a filter descriptor set as something like this开发者_开发问答:

<ria:FilterDescriptor Operator="Contains" Value="{Binding Text, ElementName=txtCustomerName}" PropertyPath="Customer.Name" IgnoredValue=""/>

This all works great, except the relationship between Order and Customer is optional i.e. an Order may not have a Customer and therefore the Customer navigation property may be null. In such a situation, when running the query, the domain data source throws a null reference exception - presumably because it's trying to traverse the Customer and get the Name value when of course the Customer is null.

Has anyone come up with a good solution to this problem?


I ended up solving this by using the MVVM equivalent to the DomainDataSource - the DomainCollectionView and its associated classes. With this, you have more control of your query composition and I therefore made my query do a null check on the Customer property before evaluation the Name property on it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜