2

在做了很多这些之后,我试图在 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")
    }
});

我不能(或不知道如何)访问 value 参数中的表达式,所以必须有其他方法吗?

感谢您提供的任何见解。

4

1 回答 1

3

您可以Property用于创建谓词:

var predicate = Predicates.Property<TwoFieldsTable, TwoFieldsTable>(f => f.Field1, Operator.Eq, f2 => f2.Field2);
var res = conn.GetList<TwoFieldsTable>(predicate);
于 2017-10-02T12:19:36.603 回答