First, you join the NameList and Category table, and then bring them into objects using ToList or AsEnumerable methods, such as
var list = (from n in db.NameList join c in db.Category on n.id equals c.nameid select new { id = n.id, Name = n.name, Categoryid = c.id }).ToList(); var list2 = from l in list group by new {l.id, l.Name} into groupings from g in groupings select new{ g.Key.id, g.Key.Name, CategoryId = string.Joing(",", groupings.Where(x=>x.NameId == g.Key.id).Select(y=>y.CategoryId)) };
The advantage of using ToList to extract data from db is that in the database you will receive only one query and all necessary records will be extracted from memory. The second statement will group these entries using id and Name and apply string.Join to CategoryId . Note that if you use the string.Join method to query Linq-to-Entities , it will fail because this method cannot be converted to an sql expression.
source share