Can’t pass collection class as parameter to RIA Services

silverlightsilverlight-3.0wcf-ria-services

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.

Best Answer

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.

Related Topic