IQToolkit + WCF Data Service

Oct 16, 2010 at 5:42 PM

I’m trying to use the IQToolkit along with WCF data services. They work very well together, but the IQToolkit isn’t able to process the following command:

OData
http:// …. Service.svc/Categories(2)/Products()

IQToolkit expression:
Queryable.Take(
Queryable.OrderBy(
   Queryable.SelectMany(
     Queryable.Where(
       Query(ns00.Category),
       element => element.CategoryID == 2
     ),
     element => ((IEnumerable<Product>)element.Products)
   ),
   element => element.ProductID
),
20
)

IQToolkit throws this exception:

The expression of type 'System.Collections.Generic.IEnumerable`1[ns00.Product]' is not a sequence

within this method
IQToolkit.Data.Common.QueryBinder.ProjectionExpression

 expr.NodeType == Convert

 Are you going to correct this problem or could you please give me an advice how I could do it myself?

Oct 17, 2010 at 10:24 AM

A question
http://.. Service.svc/Customers('ALFKI')/Orders
is translated to this expression

{Query(ns00.Customer).Where(element => (element.CustomerID == "ALFKI")).SelectMany(element => Convert(element.Orders)).OrderBy(element => element.OrderID).Take(20)}

Oct 19, 2010 at 9:30 AM

I resolved this problem. Add the code below to the
class IQToolkit.Data.Common.QueryBinder
method private ProjectionExpression ConvertToSequence(Expression expr)

Code:

case ExpressionType.Convert: {
   var oper = (expr as UnaryExpression).Operand;
   if(oper.NodeType == ExpressionType.MemberAccess) {
      var bound = this.BindRelationshipProperty((MemberExpression)oper);
      if(bound.NodeType != ExpressionType.MemberAccess)
         return this.ConvertToSequence(bound);
   }
}
goto default;