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

发布于 2024-08-22 15:42:25 字数 1253 浏览 3 评论 0原文

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

以下是 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 属性没有帮助。

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

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

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

峩卟喜欢 2024-08-29 15:42:25

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文