WorknHardr
asked on
LINQ Groub By and Return Alias ID and GroupName as Concat Data?
Difficult title indeed. I had the data returning great until including the Group By. I need to combine two columns data like so:
ID = g.Key,
Group = categoryRef.Name + "/" + categorySubRef.Name
[Output]
ID = 1, Group = Auto/Loan
ID = 2, Group = Auto/Repair
ID = 3, Group = Boat/Fuel
etc...
ID = g.Key,
Group = categoryRef.Name + "/" + categorySubRef.Name
[Output]
ID = 1, Group = Auto/Loan
ID = 2, Group = Auto/Repair
ID = 3, Group = Boat/Fuel
etc...
[code]
var groups =
(from c in context.CategoryAsgns
join r in context.CategoryRefs on c.CategoryID equals r.CategoryID
join r2 in context.CategorySubRefs on c.CategorySubID equals r2.CategorySubID
let j = new { categoryAsgn = c, categoryRef = r, categorySubRef = r2 }
orderby j.categoryRef.Name ascending
group j by j.categoryRef.Name into g
select new { ID = g.Key,
Group = categoryRef.Name +"/"+ categorySubRef.Name) }).ToList();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thx for sending down the right path
ASKER
select new {
CategoryAsgnID = g.FirstOrDefault().categor
GroupName = g.FirstOrDefault().categor
+ "/" +
g.FirstOrDefault().categor
}).ToList();