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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:32:59+00:00 2026-05-28T16:32:59+00:00

Should I always need to use FirstOrDefault to show columns not included in aggregate

  • 0

Should I always need to use FirstOrDefault to show columns not included in aggregate function?

 var creditos = from c in context.creditos
                       where c.Status == status
                       join a in context.acreditados on c.IDCredito equals a.IDCredito
                       group a by a.IDCredito into g
                       select new
                       {
                           Id = g.FirstOrDefault().creditos.IDCredito,
                           Expediente = g.FirstOrDefault().creditos.Expediente,
                           Status = (_Credito.Status)g.FirstOrDefault().creditos.Status,
                           Producto = (_Credito.Producto)g.FirstOrDefault().creditos.Producto,
                           Monto = g.Sum(Monto => Monto.Cantidad),
                           Fecha = g.FirstOrDefault().creditos.FechaInicio,
                           Tasa = g.FirstOrDefault().creditos.TasaInteres,
                           Plazo = g.FirstOrDefault().creditos.Plazo,
                           Periodo = g.FirstOrDefault().creditos.Periodo
                       };
  • 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-28T16:33:00+00:00Added an answer on May 28, 2026 at 4:33 pm

    No, not really: you could use LastOrDefault. The important thing is to get a single value to “pair up” with scalars produced in the aggregation.

    An alternative is to put these values in the key at the group by stage: if you know they would be the same, add them to the key of the group, and pull them from there during the aggregation stage.

    var creditos = from c in context.creditos
                       where c.Status == status
                       join a in context.acreditados on c.IDCredito equals a.IDCredito
                       group a by new {a.IDCredito, a.FechaInicio, a.TasaInteres, a.Plazo, a.Periodo } into g
                       select new
                       {
                           Id = g.FirstOrDefault().creditos.IDCredito,
                           Expediente = g.FirstOrDefault().creditos.Expediente,
                           Status = (_Credito.Status)g.FirstOrDefault().creditos.Status,
                           Producto = (_Credito.Producto)g.FirstOrDefault().creditos.Producto,
                           Monto = g.Sum(Monto => Monto.Cantidad),
                           Fecha = g.Key.FechaInicio,
                           Tasa = g.Key.TasaInteres,
                           Plazo = g.Key.Plazo,
                           Periodo = g.Key.Periodo
                       };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

True or not: We should always use proper capitalization and never put whole sentences
One should always use std::string over c-style strings( char * ) is advice that
I remember Google says we should always use the latest API and set the
I have previously been told that I should always use Randomize() before I use
As I understand it you should always use a TextField for a variable length
OK, I know already all the reasons on paper why I should not use
I understand that you should always use transactions. I also see that NHibernate.ITransaction implement
If it's Path_To_DocumentRoot/a/b/c.php ,should always be /a/b . I use this: dirname($_SERVER[PHP_SELF]) But it
I use preg_match_all($pattern, $string, $matches) regularly on data, and basically, I always need to
I need the user to set a number of percentage values which should always

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.