Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Help with LINQ group by

Posted on 2014-01-24
1
Medium Priority
?
385 Views
Last Modified: 2016-02-10
Hi.
I have the following statement which returns totals by SSN. I need to add another column to the result.  How do I do that?  I want to include the LASTNAME.  Any ideas?

   var query = from rawdata in myTable.AsEnumerable()
                         group rawdata by rawdata.Field<string>("SSN") into grp
                         orderby grp.Key
                         select new
                         {
                             SSN = grp.Key,
                             TOTAL = grp.Sum(r => r.Field<decimal>("SALES"))
                         
                       // WANT TO ADD LASTNAME HERE!
                       // LASTNAME IS A FIELD IN myTable

                           LASTNAME = ????????????????




                         };
0
Comment
Question by:JElster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 39806724
Hi  JElster;

This should give you the wanted results.

var query = from rawdata in myTable.AsEnumerable()
            group rawdata by rawdata.Field<string>("SSN") into grp
            orderby grp.Key
            select new
            {
                SSN = grp.Key,
                TOTAL = grp.Sum(r => r.Field<decimal>("SALES")),
                LASTNAME = grp.Select(n => n.Field<string>("LASTNAME")).FirstOrDefault()
            };

Open in new window

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question