2

I am trying to create what seems like a relatively simple predicate statement for Dapper-Extensions in C# after doing a good number of these, but in one case I need to compare two fields rather than a field and a fixed object value:

multiPred.Add<ChargingProfile>(new PredicateGroup
{
    Operator = GroupOperator.And,
    Predicates = new List<IPredicate>
    {
        Predicates.Field<ChargingProfile>(f => f.EndDt, Operator.Eq, null, true),

        // the below statement should check if f.NextChargeDt is greater than f.EndDt
        // (string value is obviously not correct, but to illustrate)
        Predicates.Field<ChargingProfile>(f => f.NextChargeDt, Operator.Gt, "f.EndDt")
    }
});

I can't (or don't know how to) access the expression in the value parameter, so there must be some other way of doing this?

Thanks for any insights you can offer.

k3davis
  • 985
  • 12
  • 29

1 Answers1

3

You can use Property for creating a predicate:

var predicate = Predicates.Property<TwoFieldsTable, TwoFieldsTable>(f => f.Field1, Operator.Eq, f2 => f2.Field2);
var res = conn.GetList<TwoFieldsTable>(predicate);
Michael
  • 1,027
  • 10
  • 22
  • 1
    Thanks Michael. I used this information to update the documentation on the Dapper-Extensions wiki, where this type of predicate was just marked "TODO": https://github.com/tmsmith/Dapper-Extensions/wiki/Predicates – k3davis Oct 02 '17 at 13:05