问题
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)
at System.Data.Services.Client.UriWriter.VisitQueryOptionExpression(FilterQueryOptionExpression fqoe)
at System.Data.Services.Client.UriWriter.VisitQueryOptions(ResourceExpression re)
at System.Data.Services.Client.UriWriter.VisitResourceSetExpression(ResourceSetExpression rse)
at System.Data.Services.Client.UriWriter.Translate(DataServiceContext context, Boolean addTrailingParens, Expression e, Uri& uri, Version& version)
at System.Data.Services.Client.DataServiceQueryProvider.Translate(Expression e)
at System.Data.Services.Client.DataServiceQuery`1.Execute()
at System.Data.Services.Client.DataServiceQuery`1.GetEnumerator()
at System.Data.Services.Client.DataServiceQuery`1.System.Collections.IEnumerable.GetEnumerator()
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