Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9150971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:41:14+00:00 2026-06-17T11:41:14+00:00

I am trying to sum a column and get details member wise My table

  • 0

I am trying to sum a column and get details member wise

My table data is

id   membername     cost
1   a               100
2   aa              100
3   a               100
4   aa                0
5   b               100

In Entity Framework I try to sum cost column and get result like this

membername             totalcost
a                      200
aa                     100
b                      100

then I am doing this

var result = from o in db.pruchasemasters.Where(d => d.memberid == d.membertable.id && d.entrydate >= thisMonthStart && d.entrydate <= thisMonthEnd)
                     group o by new { o.membertable.members } into purchasegroup
                     select new
                     {
                         membername = purchasegroup.Key,
                         total = purchasegroup.Sum(s => s.price)
                     };

How do I read the results and is my code right or not?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:41:16+00:00Added an answer on June 17, 2026 at 11:41 am

    Something like that will work

        var result = db.pruchasemasters.GroupBy(o => o.membername)
                       .Select(g => new { membername = g.Key, total = g.Sum(i => i.cost) });
    
        foreach (var group in result)
        {
            Console.WriteLine("Membername = {0} Totalcost={1}", group.membername, group.total);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I´m trying to get a sum from the column of the repeated values that
I'm trying to get the sum of a column. My Schema is as below...
I am trying populate H3 with the sum of column E for rows that
I am trying on do a sum of the column Market Capitalization but I'm
I'm trying to do a group by using Zend framework. Here's my code: $table
I'm trying to add all the values in a column to get the total
I'm trying to get the MAX on a column which is generated dynamically using
First of all here what i'm trying to accomplish: Get the sum of etp_product.price
I have some trouble trying to get the values of the first column with
I am trying to get the cumulative sum of a variable (v) for groups

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.