can't pass collection class as parameter to RIA Services

浪子不回头ぞ 提交于 2019-12-08 04:16:12

问题


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."

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();
}

The filter options class is defined as:

[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; }

}

Adding the DataContract and DataMember attributes did not help.

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.)

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.


回答1:


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

Edit: 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.



来源:https://stackoverflow.com/questions/2330085/cant-pass-collection-class-as-parameter-to-ria-services

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!