如何在WCF数据服务中编写“In”查询?

时间:2011-02-03 13:11:17

标签: entity-framework wcf-data-services

如何在 Ado.Net WCF数据服务中编写'In'查询?我试过以下代码。

IList<int> orderIds = new List<int> { 59810, 59811, 59812, 59813, 59814 };
var lstorders = _context.Orders
                        .Where(o => orderIds.Contains(o.customerId))
                        .ToList<Orders>();

但上面的代码不起作用。我收到了以下错误。

  

测试'MyTest'失败:System.NotSupportedException:The   表达式(([10007] .customerId!=   null)而且   值(System.Collections.Generic.List 1[System.Int32]).Contains([10007].customerId.Value)) is not supported. 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.DataServiceALinqExpressionVisitor.Visit(Expression exp) 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()       在System.Data.Services.Client.DataServiceQuery 1.GetEnumerator() at System.Collections.Generic.List 1..ctor(IEnumerable 1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable 1   源)

2 个答案:

答案 0 :(得分:3)

答案 1 :(得分:1)

WCF数据服务'WHERE IN','WHERE NOT IN'扩展方法sample