tags:

views:

37

answers:

0

I have got an error:

Unable to cast object of type 'System.Linq.Expressions.MethodCallExpression' to type 'SubSonic.Linq.Structure.ProjectionExpression'

when I try to call distinct in collection of orders:

var distinctOrders = user.Orders.Distinct(new OrderComparer()).ToList();

OrderComparer class has a standard implementation like:

private class OrderComparer: IEqualityComparer<Order>
{
    public bool Equals(Order x, Order y)
    {
        if (ReferenceEquals(x, y)) return true;

        if (ReferenceEquals(x, null) || ReferenceEquals(y, null))
            return false;

        return x.Name== y.Name;
    }

    public int GetHashCode(Order order)
    {
        if (ReferenceEquals(order, null)) return 0;

        int hashOrderQuery= order.Name== null ? 0 : order.Name.GetHashCode();

        return hashOrderQuery;

    }
}

Why does I get this strange exception? Thanks.