谓词将两个字段与Dapperextensions进行比较



我正在尝试创建一个相对简单的谓词语句,用于在执行大量之后,用于C#中的dapper-extensions,但是在一种情况下,我需要比较两个字段,而不是字段和固定对象值:

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")
    }
});

我无法(或不知道如何)访问值参数中的表达式,因此必须有其他方法?

感谢您提供的任何见解。

您可以使用Property来创建谓词:

var predicate = Predicates.Property<TwoFieldsTable, TwoFieldsTable>(f => f.Field1, Operator.Eq, f2 => f2.Field2);
var res = conn.GetList<TwoFieldsTable>(predicate);

最新更新