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 7536781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:40:11+00:00 2026-05-30T06:40:11+00:00

I am not a pro on Linq but trying to understand. How to write

  • 0

I am not a pro on Linq but trying to understand. How to write this code (written in VB) in C#

Dim x = From p in db.YourClass _

Where p.fl1 = cn1 And p.f12 = cn2

Select _

sum1 = x.Sum(Function(y) y.fl1), _

sum2 = x.Sum(Function(y) y.fl2), _

sum3 = x.Sum(Function(y) y.fl3)

what i am trying to achieve is this,

select sum(fl1),sum(fl2),sum(fl3)

where fl1 =cn1 and fl2=cn2

The above sample found here

  • 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-05-30T06:40:13+00:00Added an answer on May 30, 2026 at 6:40 am
    var x = from p in db.YourClass 
            where p.fl1 == cn1 && p.f12 == cn2
            select p;
    
      var sum1 = x.Sum(y=>y.fl1), 
    
      var sum2 = x.Sum(y=>y.fl2), 
    
      var sum3 = x.Sum(y=>y.fl3)
    

    Edit: In one query I think this can work fast:

    var x = (from p in db.YourClass 
    
            select new 
            {
             s1 = db.YourClass.Where(y=> y.fl1 == cn1 && y.f12 == cn2).Sum(y=>y.fl1),
             s2 = db.YourClass.Where(y=> y.fl1 == cn1 && y.f12 == cn2).Sum(y=>y.fl2),
             s3 = db.YourClass.Where(y=> y.fl1 == cn1 && y.f12 == cn2).Sum(y=>y.fl3)
            }).First();
    
     int sum1 = x.s1, sum2 = x.s2, sum3 = x.s3;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not a pro in Regex, therefore I'm having a difficulty translating this regex
Not exactly about programming, but I need help with this. I'm running a development
I'm not a pro with swing layout managers and this behavior is completely baffling
I'm not quite pro with encodings, but here's what I think I know (though
So I have an issue with some PHP code, and I'm not a pro
I'm not a pro with regexp and especially in this specific context. Any idea
First of all, im new here, and im (not) a pro ;) (but i
I'd prefer a commercial solution. So not NHibernate. Now i'm playing with LLBLGen pro
Not sure if this counts as programming related, it's a tool that I use.
Not that level of failure indeed. I just completed the 4 part tutorial from

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.