XAML/Silverlight:将集合(例如 ListBox.SelectedItems)传递给 DomainService 方法
我需要将一组值传递给 DomainService 方法。我希望服务方法如下所示:
IQueryable<Person> GetPeople( Nullable<DateTime> MinDOB, IList<String> Ethnicities )
{
return
from
Person item in ObjectContext.People
where
item.DOB >= MinDOB
&& Ethnicities.Contains( item.ETHNICITY )
select
item;
}
查询在没有参数的情况下工作正常,并且在仅使用 DOB 参数的情况下工作正常。在 XAML 中,我可以通过 QueryParameters/QueryParameter 将 DOB 参数作为参数传递给服务方法,或者我可以将服务方法设置为 nonary,让它返回所有内容,并将 DOB 参数粘贴到 FilterDescriptor 中。两者都有效(有一个警告:我无法弄清楚如何使 FilterDescriptor XAML 的 IgnoredValue 属性与 null DateTime 一起使用)。到目前为止,一切都很好。但日期是标量,而 ListBox.SelectedItems 不是标量。
我在服务方法上不断收到“必须是预定义的可序列化类型之一”错误,如上面定义的任何内容(无论如何,MSDN 中哪里有这些禁止的猩红类型的列表?),并且以下内容也不起作用:
<ria:DomainDataSource.FilterDescriptors>
<ria:FilterDescriptor PropertyPath="ETHNICITY" Operator="IsContainedIn" Value="{Binding ElementName=_lbEthnicities, Path=SelectedItems}" />
</ria:DomainDataSource.FilterDescriptors>
它抛出“Operator 'IsContainedIn' 与操作数类型 'String' 和 'ObservableCollection`1' 不兼容 ---> System.ArgumentNullException:值不能为 null。”
我是否应该放弃并只定义客户端 C# 代码以将选定的列表框值填充到带有分隔符的字符串中,或者类似的内容?我试图将声明性的东西推到尽可能远的地方,但在某个地方必须有一个限制。
I need to pass a set of values to a DomainService method. Here's what I'd like the service method to look like:
IQueryable<Person> GetPeople( Nullable<DateTime> MinDOB, IList<String> Ethnicities )
{
return
from
Person item in ObjectContext.People
where
item.DOB >= MinDOB
&& Ethnicities.Contains( item.ETHNICITY )
select
item;
}
The query works fine with no parameters, and with just the DOB parameter it works fine. In the XAML, I can pass the DOB parameter via QueryParameters/QueryParameter as a parameter to the service method, or alternatively I can make the service method nonary, have it return everything, and stick the DOB parameter in a FilterDescriptor. Both work (with one caveat: I can't figure out how to make the FilterDescriptor XAML's IgnoredValue attribute work with a null DateTime). So far so good. But dates are scalar, and ListBox.SelectedItems isn't.
I keep getting the "must be one of the predefined serializable types" error on the service method as defined anything like the above (where's there a list of those forbidden scarlet types in MSDN, anyhow?), and the following doesn't work either:
<ria:DomainDataSource.FilterDescriptors>
<ria:FilterDescriptor PropertyPath="ETHNICITY" Operator="IsContainedIn" Value="{Binding ElementName=_lbEthnicities, Path=SelectedItems}" />
</ria:DomainDataSource.FilterDescriptors>
It throws "Operator 'IsContainedIn' incompatible with operand types 'String' and 'ObservableCollection`1' ---> System.ArgumentNullException: Value cannot be null."
Should I give up and just define client C# code to stuff the selected listbox values into a string with delimiters, or something like that? I'm trying to push the declarative thing here as far as it'll go, but there's got to be a limit somewhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是说 IsContainedIn 需要一串逗号分隔的值而不是一个对象。
看一下使用 String.Join 创建字符串,然后绑定到该字符串。您仍然可以将其作为页面上的属性。
What that's saying is that the IsContainedIn requires a string of comma separated values rather than an object.
Have a look at using String.Join to create the string and then bind to that. You could still have it as a property on your page.