How can I include one expression in another expression?

后端 未结 3 1020
悲哀的现实
悲哀的现实 2021-01-21 05:07

I have a DateRange class that I\'d like to apply to an IQueryable as a where predicate, automatically using the begin and end dates and automatically using an open or closed int

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-21 05:39

    You'll have to hand-craft dateField >= BeginDate using Expression class methods.

    (...)
        if (BeginInclusive)
        {
            var greaterOrEqual =
                Expression.Lambda>(
                    Expression.GreaterThanOrEqual(
                        dateField.Body,
                        Expression.Constant(BeginDate)),
                    dateField.Parameters);
    
            result = result.Where(greaterOrEqual);
        }
    (...)
    

    Similarly for the other cases.

提交回复
热议问题