I have a model that is stored in a list:
public class OrderDataModel
{
public string Product { get; set; }
public string Registry { get; set; }
public string ProjectID { get; set; }
public string ProjectName { get; set; }
public string ProjectTypeProtocol { get; set; }
public string ProjectGeography { get; set; }
public string Vintage { get; set; }
public string CCBQualified { get; set; }
public string CorsiaEligible { get; set; }
public int? BidQty { get; set; }
public decimal? Bid { get; set; }
public int? AskQty { get; set; }
public decimal? Ask { get; set; }
public string? ExecutionVenue { get; set; }
}
I have a list of the above. I would like to get the Max ‘Bid’ amount and the Mix ‘Ask’ amount for all that have matching ‘Product’, ‘ProjectID’, ‘Vintage’, ‘CCBQualified’, ‘CorsiaEligible’, and ‘ExecutionVenue’ and only if the count is more than one. So if there are items that don’t have matching of those, disregard those items.
I tried writing something like this:
ordersModel
.GroupBy(a => new {a.ProjectID, a.Product, a.Vintage, a.CCBQualified, a.CorsiaEligible, a.ExecutionVenue})
.Select(b => new {ProjectID = b.Key.ProjectID,Product= b.Key.Product, Vintage = b.Key.Vintage, CCBQualified = b.Key.CCBQualified, ExecutionVenue = b.Key.ExecutionVenue, max = b.Max(c => c.Bid), min = b.Min(c => c.Ask)});
I’m getting a lot of results back without the grouping and a lot of the ProjectID’s are blank. I don’t think I’m doing the select portion correctly and how do I denote to select only if the ones that have all those values matching.
Saif Ahsanullah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.