Hi all, I hope someone could help me out with this linq query.
I am new to Linq and having a hard time figuring out how to do the
CountSoldByColor. What I need is to be able to do the count where from the grouped items and alo include a join table Color where the Name of the color is say "blue".
If you need more info please don't hestiate to ask. Thanks in advance!
Cars
----
ID
ModelID
Year
Status
Color
----
ID
CarID
Name
- from s in
- (
- from t in Cars
- select new { t }
- ) group s by new { s.t.ModelID, s.t.Year } into g
- select new
- {
- Model = (from k in Models where k.ID == g.Key.ModelID select k.Name),
- Year = g.Key.Year,
- CountSold = g.Count(p => (p.t.Status == "Sold")),
- // Need to Count the number of Cars that were Sold and is Color blue (lets say for example and where Color is another table)
- CountSoldByColor =
- }
Faisal PathanPosted Jul 4, 2019, 12:49 AM
join clr in Colors on c.ID equals clr.PlaceID into clrCar
join mdl in Models on c.ModelID equals mdl.ID into mdlCar
select new
{
Model = mdl.Name,
CountSold = c.Count(p => (p.t.Status == "Sold")),
CountTalk = clrCar.Count(p => (p.t.ColorName == "Blue"))
Akash GhadagePosted Jul 4, 2019, 8:00 AM
New BeePosted Jul 4, 2019, 7:26 AM