I was trying to do a join and then a group by, My grouped information that is returned is great! works like a charm, but i still need access to values outside the grouping, if that makes sense..
I found an example on stackoverflow, which probably explains it better
var query = from c in context.Contacts
join o in context.Orders on c.Id equals o.CustomerId
select new
{
Contact = c,
Order = o
} into ContactAndOrder
group ContactAndOrder by ContactAndOrder.Order.Id into g
select new
{
g.Key,
ContactWhatever = g.Sum(co => co.Contact.Whatever),
OrderWhatever = g.Sum(co => co.Order.Whatever)
};
Now this seems to work great, problem is in my situation the co.Order.Whatever is a string so i get an error saying can’t convert string to int, this i understand as the aggregate function Sum expects a int….
My question really is, is there an aggregate function or something similar to i can get the value of co.Order.Whatever (a string in my case )
The problem being is once the group by has been done i lose “c” and “o”
I hope someone can help.
thanks in advance
if it’s always the same in the group, the First will be enough…
else use @Andrei Answer
or