i have this simple class:
public class JDEItemLotAvailability
{
public string Code { get; set; }
public int ShortCode { get; set; }
public string Description { get; set; }
public string PrimaryUnitCode { get; set; }
public string BranchPlant { get; set; }
public string Location { get; set; }
public string Lot { get; set; }
public int AvailableQuantity { get; set; }
}
This DAL method in my BLL returns a list of them:
var returnedLotList = _JDE8dal.GetLotAvailabilityAsList(_lot);
I want to do the following in the returned list and i want to do it in the most “elegant” LINQ way.
I want to check if among the list there is a record that matches specific criteria. I have thought of something like this:
var query =
returnedLotList.Where(l => l.AvailableQuantity != 0 && l.BranchPlant == _mcu && l.Location == _locn)
.OrderByDescending(l => l.AvailableQuantity);
BUT i want to say that if the above query does not return results i want to take the first of the rest of the list entries.
How can i do that?
You can just use
DefaultIfEmpty