1

这是 Silverligh 中的代码。我正在尝试从 wcf 数据服务获取数据:

    public DataServiceQuery<Group> GetGroupsByDisplayName(string groupPartitionKey, string displayName)
    {
        DataServiceQuery<Group> query = (DataServiceQuery<Group>)(from g in this.Groups
                                                                  where g.PartitionKey == groupPartitionKey & g.DisplayName.Contains(displayName) == true
                                                                  select g);
        return query;
    }

这是该查询的结果:

http://127.0.0.1:8080/DataService/WcfDataService.svc/Groups()?$filter=PartitionKey%20eq%20'Family'%20and%20substringof('text',DisplayName)%20eq%20true

这是我的 wcf 数据服务使用该链接的响应:

<?xml version="1.0" encoding="utf-8" standalone="yes"?><error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><code></code><message xml:lang="en-US">Not Implemented</message><innererror><message>The expression (([10007].PartitionKey == "Family") And (IIF(([10007].DisplayName == null), null, Convert([10007].DisplayName.Contains("text"))) == True)) is not supported.</message><type>System.NotSupportedException</type><stacktrace>   at System.Data.Services.Client.ExpressionWriter.ExpressionToString(DataServiceContext context, Expression e)&#xD;
   at System.Data.Services.Client.UriWriter.VisitQueryOptionExpression(FilterQueryOptionExpression fqoe)&#xD;
   at System.Data.Services.Client.UriWriter.VisitQueryOptions(ResourceExpression re)&#xD;
   at System.Data.Services.Client.UriWriter.VisitResourceSetExpression(ResourceSetExpression rse)&#xD;
   at System.Data.Services.Client.UriWriter.Translate(DataServiceContext context, Boolean addTrailingParens, Expression e, Uri&amp; uri, Version&amp; version)&#xD;
   at System.Data.Services.Client.DataServiceQueryProvider.Translate(Expression e)&#xD;
   at System.Data.Services.Client.DataServiceQuery`1.Execute()&#xD;
   at System.Data.Services.Client.DataServiceQuery`1.GetEnumerator()&#xD;
   at System.Data.Services.Client.DataServiceQuery`1.System.Collections.IEnumerable.GetEnumerator()&#xD;
   at System.Data.Services.WebUtil.GetRequestEnumerator(IEnumerable enumerable)</stacktrace></innererror></error>

我究竟做错了什么?我需要使用“string.Contains”来获取数据(这是一个搜索屏幕)。如果我删除“string.Contains”部分,那么它工作正常。我正在使用 Azure 表存储、Wcf 数据服务、OData V1、Silverlight 5、Visual Studio 2012。

4

0 回答 0