locked
Odata expand and filter problem for projection RRS feed

  • Question

  • Hi,

    I have gone through the post, http://social.msdn.microsoft.com/Forums/vstudio/en-US/d0ca8634-0bfb-4c6a-9680-20a83bab49e8/odata-expand-and-filter-problem?forum=wcf relating to applying filters on expanded collection.

    According to the post we can apply Any or All Quantifier on child collections. This is perfectly working on trying to apply on entities directly exposed from DB. but receiving below NotSupported Exception on trying to apply on projections,

    Cannot compare elements of type 'System.Linq.IEnumerable`1'. Only primitive types, enumeration types and entity types are supported

    Url tried:

    ~/Customers?$expand=Orders&$filter=Orders/any(o: o/OrderId eq 1)

    Projection class:

    public class Customer

    {

    public int ID {get;set;}

    public IEnumerable<Order> Orders {get;set;}

    }

    DB to Projection conversion:

    (from c in context.Cutomers
                select new Customer()
                {
      ID = c.ID,
      Orders = c.Orders.select(x => new Order()
                    {
       OrderId = x.OrderId
                    }).AsQuerable()
                }).AsQuerable();

    Thursday, October 17, 2013 5:37 PM

All replies

  • Hi,

    Above code worked on materializing the list using .ToList() which means entire data will be fetched from DB. Is this expected any efficient way to over come this?

    (from c in context.Cutomers.ToList()
                select new Customer()
                {
      ID = c.ID,
      Orders = c.Orders.select(x => new Order()
                    {
       OrderId = x.OrderId
                    }).AsQuerable()
                }).AsQuerable();

    Friday, October 18, 2013 12:16 AM
  • Hi,

    Please try to post it in the wcf forums.

    Friday, October 18, 2013 9:02 AM