How to “let” in lambda expression?

后端 未结 4 1762
无人及你
无人及你 2020-12-08 00:27

How can I rewrite this linq query to Entity on with lambda expression?
I want to use let keyword or an equivalent in my lambda expression.

var r         


        
4条回答
  •  悲哀的现实
    2020-12-08 00:53

    Another option is to define this extension method:

    public static class Functional
    {
        public static TResult Pipe(this T value, Func func)
        {
            return func(value);
        }
    }    
    

    Then write your query like this:

    var results = Stores
        .Where(store => store.Sales.Average(s => s.Price)
            .Pipe(averagePrice => averagePrice < 500 && averagePrice > 250));
    

提交回复
热议问题