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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:10:17+00:00 2026-06-05T23:10:17+00:00

I have to show one row per one bill in my program, but one

  • 0

I have to show one row per one bill in my program, but one bill has more than 1 sub-bills. I would like to group information from 2 tables in one DataGridView. 1 row must show grouped info about all sub-bills.
Only 2 columns are more complex than other: “Description” and “Sum”. “Description” must contain all of descriptions of sub-bills and be delimited by new-line. I made it next way:

var documentQuery = (from doc in entities.Bas_DocumentData
                select new 
                        {
                            DocumentNum = doc.DocumentNum,
                            DocumentDate = doc.DocumentDate,
                            Description = doc.Bas_BonusData.Select(t => t.Description),
                            BillsCount = doc.Bas_BonusData.Count,
                            SupplierNum = doc.Bas_BonusData.Select(cred => cred.SupplierNum).FirstOrDefault(),
                            Debitor = doc.Bas_BonusData.Select(deb => deb.DebitorNum).FirstOrDefault(),
                            Manager = doc.Bas_BonusData.Select(manager => manager.ManagerName).FirstOrDefault(),
                            SupplierName = doc.Bas_BonusData.Select(supp => supp.SupplierName).FirstOrDefault(),
                            Sum = doc.Bas_BonusData.Sum(bill => bill.Price),
                            IsPrinted = doc.isPrinted,
                            IsSent = doc.isSent,
                            NotSummarize = doc.NotSummarize
                        }).OrderBy(key => key.DocumentNum)
                        .ToList()
                        .Select(q => new AcceptedBonusProjection
                        {
                            DocumentNum = q.DocumentNum,
                            DocumentDate = q.DocumentDate,
                            Description = String.Join("\n\r", q.Description.ToArray()),
                            BillsCount = q.BillsCount,
                            SupplierNum = q.SupplierNum,
                            Debitor = q.Debitor,
                            Manager = q.Manager,
                            SupplierName = q.SupplierName,
                            Sum = q.Sum,
                            IsPrinted = q.IsPrinted,
                            IsSent = q.IsSent,
                            NotSummarize = q.NotSummarize
                        });

Is there better way to achieve my goal? Which way can I shorten this query?

  • 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-05T23:10:19+00:00Added an answer on June 5, 2026 at 11:10 pm

    The first half (anony. struct) is not needed at all:

    var documentQuery = 
       entities.Bas_DocumentData
       .OrderBy(key => key.DocumentNum)
       .Select(q => new AcceptedBonusProjection
                            {
                                DocumentNum = q.DocumentNum,
                                /* same as in your select snipped here as it does not add value */
                                NotSummarize = q.NotSummarize
                            })
       .ToList();
    

    Remark:
    Please note that you do some subqueries that might not scale well (selecting from another table in your queries, for example doc.Bas_BonusData.Select(manager => manager.ManagerName).FirstOrDefault()) – this will NOT be translated into a inner/outer-join and will result in many DB-queries. Eager loading will not solve this problem!
    You should consider using a SQL-View/StoredProcedure/LINQ-Join Statements to change this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a grid that has multiple rows. I want to hide/show one of
I have one SubjectTabActivity and i need to show listview on this activity. But
I am using below URL to show line chart but one thing I have
I need to return only the names that have more than one franchise. I
I have one text box and i have to show minimum date of the
I have to show several brands on my google maps, one can be a
I have a page with many tooltips. I want to show/hide every one seperatly
I have a page set up to show only posts from one category, which
I have several forms on one page which are submitted using ajaxForm and show
I have two grids, thay both have one store. I need to show everything

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.