mercredi 22 août 2018

linq query dynamically inside where

I would like to change dynamically a specific part of the query - depending on the result of if condition. I would be glad for your help:

if (someCondition == true)
    var ADDITION_FILTER_CRITERIA = && z.t.Name == Keyword
else
    var ADDITION_FILTER_CRITERIA = "";

                var ToursPerDestination = await _context.Tours
                 .Join(_context.CruiseDestinations, t => t.DestinationId, d => d.DestinationId, (t, d) => new { t, d })
                 .Where(z => z.d.CruiseId == SelectedCruise.CruiseId ADDITION_FILTER_CRITERIA )
                 .Select(z => new ToursViewModel()
                 {                   
                     Name = z.t.Name,                   
                 }).OrderByDescending(z => z.Name).ToListAsync().ConfigureAwait(false);





Aucun commentaire:

Enregistrer un commentaire