无法将集合类作为参数传递给

无法将集合类作为参数传递给

本文介绍了无法将集合类作为参数传递给 RIA 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将应用程序定义的对象列表传递给 RIA 服务时遇到问题.我收到一个编译错误,提示域操作条目‘GetPagedExams’的错误参数‘过滤器’必须是预定义的可序列化类型之一."

I'm having a problem passing an list of application-defined objects to RIA services. I get a compile error saying "Error Parameter 'filters' of domain operation entry 'GetPagedExams' must be one of the predefined serializable types."

这是 DomainService 中的查询:

Here's the query in the DomainService:

[Query]
public IQueryable<ExamEntity> GetPagedExams(int first, int pageSize, List<FilterOptions> filters, List<string> sortDescriptions)
{
    return Context.Exams.GetPagedExams(first, pageSize, filters, sortDescriptions).Data.AsQueryable();
}

过滤器选项类定义为:

[DataContract]
[Serializable]
public class FilterOptions
{
    public enum FilterAction
    {
        Equals,
        NotEquals,
        LessThan,
        LessThanOrEquals,
        GreaterThan,
        GreaterThanOrEquals,
        Like,
        NotLike,
        IsNull,
        IsNotNull
    }

[DataMember]
[Key]
public string FieldName
{ get; set; }

[DataMember]
public FilterAction FilterOp
{ get; set; }

[DataMember]
public object FieldValue
{ get; set; }

}

添加 DataContract 和 DataMember 属性没有帮助.

Adding the DataContract and DataMember attributes did not help.

我需要传递可变数量的过滤约束,这些约束将作为服务器端 SQL 查询的一部分进行组装,因此对象列表几乎是必需的.(是的,下面是原始 SQL,数据库可以是 SQL Server 或 Oracle.所以我不能使用 LINQ,Silverlight 客户端也不知道我使用的是哪个数据库.)

I need to pass a variable number of filtering constraints that will be assembled as part of an SQL query on the server side, so a list of objects is just about a necessity. (Yes, it's raw SQL underneath, and the database can be either SQL Server or Oracle. So I can't use LINQ, and the Silverlight client can't know which database I'm using.)

有什么建议吗?我正要尝试从客户端传递一个 XML 序列化,并在服务器上重新组合它.这真的不是我的首选......

Any suggestions? I'm just about to try passing an XML serialization from the client, and re-hydrating it on the server. That's really not my preferred option....

当我为过滤器传递单个字符串而不是集合时,这是一个有效的查询.所以我知道问题出在自定义集合上.

This was a working query when I was passing a single string for a filter, rather than a collection. So I know the problem is strictly with the custom collection.

推荐答案

这似乎是 RIA 服务的当前限制.看看 MSDN 论坛

It seems to be a current limitation of RIA Services. Have a look at MSDN forum

刚刚在另一个项目中再次遇到此问题.一个不太好的解决方法是使用 [Invoke] 方法,该方法可以采用 List 参数并可以返回 IEnumerable,但 RIA Services不发回 X 的导航属性.

just had this issue again in another project. A not-so-great work-around is to use an [Invoke] method, which can take a List parameter and can return a IEnumerable<X>, but RIA Services does not send back the navigation properties of X.

这篇关于无法将集合类作为参数传递给 RIA 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 03:15