0

I want to reuse the following code:

readonly Func<QueryContainerDescriptor<OemCatalogModel>, QueryContainer> query = q => q.DateRange(d => d.GreaterThanOrEquals(startDate).LessThanOrEquals(endDate));

For example, one of methods:

public async Task GetCount(DateTimeOffset? startDate, DateTimeOffset? endDate, string eventName)
{
    var count = await _elasticClient.CountAsync<OemCatalogModel>(c => c.Index(indexName)
            .Query(query)
            .Query(q => q.Match(m => m.Field(f => f.Event).Query($"{eventName}")))
            );
}

What should signature of delegate for using this arguments? I trying implement following:

var count = await _elasticClient.CountAsync<OemCatalogModel>(c => c.Index(indexName)
                .Query(query(startDate, endDate))
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user6408649
  • 1,227
  • 3
  • 16
  • 40
  • 2
    The signature should be the same as the method with regard to the amount and type of parameters, as well as the return type. If you feel kinky, you might change the order of the parameters, but that's pretty much the only flexibility you have here... –  Sep 03 '22 at 21:33
  • @MySkullCaveIsADarkPlace I attempt implement something like this https://stackoverflow.com/questions/50912134/reuse-query-for-both-count-and-search-in-nest-elasticsearch – user6408649 Sep 03 '22 at 21:54

0 Answers0