vkhorikov / SpecificationPattern

Implementation of the Specification Pattern in C#
304 stars 73 forks source link

Property <some prop from class X> is not defined for type <some prop from class Y> (Parameter 'property') #4

Open macik1423 opened 9 months ago

macik1423 commented 9 months ago

In my specification I have some expression:

public class OrderModelSapNumber : WhereSpecification<OrderModel>
{
    private readonly string Sap;

    public OrderModelSapNumber(string sap)
    {
        Sap = sap;
    }

    public override Expression<Func<OrderModel, bool>> ToExpression()
    {
        if (Sap == null || Sap == "") return o => true;
        return o => o.OrderItems.Any(oi => oi.Component.SAP != null && oi.Component.SAP.Contains(Sap, StringComparison.InvariantCultureIgnoreCase));
    }
}

But when it's run there is an issue "Property 'API.Model.Order.ComponentModel Component' is not defined for type 'API.Model.Order.OrderModel' (Parameter 'property')". I think there is a problem with lambda. Am I right the lambda doesn't see Component property?

Edit: the error is in line exprBody = (BinaryExpression)new ParameterReplacer(paramExpr).Visit(exprBody); in ToExpression() method.