Error in WCF Data Service when using string.Contains within LINQ statement from Silverlight

…衆ロ難τιáo~ 提交于 2019-12-11 07:21:49

问题


This is the code within Silverligh. I'm trying to get data from a wcf data service:

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

This is the result of that query:

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

This is the response from my wcf data service using that link:

<?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>

What am I doing wrong? I need to use "string.Contains" to get data (it's a search screen). If I remove the "string.Contains" part, then it works fine. I'm using Azure Table Storage, Wcf Data Services, OData V1, Silverlight 5, Visual Studio 2012.

来源:https://stackoverflow.com/questions/13057260/error-in-wcf-data-service-when-using-string-contains-within-linq-statement-from

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