1

我有一个使用 EF 模型运行 RIA 服务的 C#.NET Silverlight 3.0 客户端。我正在尝试在客户端上设置一个高级搜索系统,以便用户可以说,我希望字段(属性)“Foo1”具有值“Bar1”等。

我想使用一种与此类似的灵活、动态的方法。问题是我不能将 IQueryable 作为 ServiceOperation 参数或域服务参数传递。IE 这不起作用:

[ServiceOperation()]
public int GetFooCount(string category, IQueryable<Foo> search)
{
    int fooCount;
    if (search != null)
    {
        IQueryable<Foo> filteredFooSet = this.Context.FooSet.Intersect(search);
        fooCount = (from foo in filteredFooSet
                    where foo.Category == category
                    select foo).Count();
    }
    else
    {
        fooCount = (from foo in this.Context.ContactSet
                    where foo.Category == category
                    select foo).Count();
    }

    return fooCount;
}

任何人都可以提出一种让这种方法发挥作用的方法或另一种(更好的)方法吗?目标是一个灵活的搜索控件,可以应用于多个特定实体类型。

4

1 回答 1

1

我认为您最好的选择是使用Dynamic Linq Library。使用该库,您可以将 where 子句作为字符串传递,然后使用该库将其用于您的 EF 数据。

于 2009-11-11T17:39:25.153 回答