Search code examples
c#linqentity-framework-4

Return additional column in Linq Query?


I have this Linq query:

var area = db.MyDbSet
    .Where(s => s.langid == langid)
    .GroupBy(s => s.Title)
    .Select(g => new { Title = g.Key })
    .Select(s => s.Title);

I want to return another column from the same table, its called: CodeId.

I am noob Linq programmer and quite lost in all those mish-mash things in C# so I can't really understand what should I do.

Can somebody help me how to return the another column from the same table with the same query call?


Solution

  • This may help you :

     var area = db.MyDbSet
                        .Where(s => s.langid == langid)
                        .GroupBy(s => s.Title)
                        .Select(g => new { Title = g.Key, CodeId = g.FirstOrDefault().CodeId });