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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:12:17+00:00 2026-06-10T10:12:17+00:00

I am trying to use two linq-to-SQL statements to return data to an array

  • 0

I am trying to use two linq-to-SQL statements to return data to an array from a database that I can use in a jQuery call. I can get the Json to return one array but I cannot get it to return the second array that contains the amounts that I need to list.

You see what I am doing is I am creating a treeview that lists Areas, projects and subprograms for each section. Every Area has a total amount spent, and every project has a total amount spent and every subprogram has a total amount spent. I have been able to get the total amount spent for the subprograms but the projects are a different story since I must use the same controller that I use to display the subprograms to display the totals for each project. It looks a little like this.

Area------------Jan--Feb--March--April--May--June--July--Aug--Sept--Oct--Nov--Dec

+Project--------Jan--Feb--March--April--May--June--July--Aug--Sept--Oct--Nov--Dec

++Sub-Program1--Jan--Feb--March--April--May--June--July--Aug--Sept--Oct--Nov--Dec

++Sub-Program2--Jan--Feb--March--April--May--June--July--Aug--Sept--Oct--Nov--Dec

Since the project amount is a sum of the subprogram amount and is in a different table than where the sub-programs are listed I am having difficulty getting the second array filled. The code below is from my controller and shows how I pull the data for the array that fills int the Sub-Programs names.

[Authorize]
        public virtual ActionResult getAjaxPGs(string SP = null, string PG = null)
        {

            if (SP != null)
            {
                var PGList = from x in db.pg_mapping
                             where x.PG_SUB_PROGRAM == SP 
                             select x;
                                 //select x.PG.Distinct().ToArray(); // I wanted to combine the PGRow = line below with the linq to SQL code above but it didn't like the .ToArray() 


                var PGRow = PGList.Select(x => new { x.PG }).Distinct().ToArray();

                return Json(PGRow, JsonRequestBehavior.AllowGet);

            }


            return View();
        }

So this code here finds and outputs the sub-programs names in place of Sub-Program1 and Sub-Program2. This part need to stay so that it will output the correct subprogram names but now I need to add code that will output the amount total at the project level. I thought that I could just add this code to the controller and return two arrays but I am not doing it right and none of the ways I have tried has worked.

var AmountList = from x in db.Spend_Web
where x.PG == PG
group x by new { x.ACCOUNTING_PERIOD, x.PG, x.Amount } into pggroup
select new { accounting_period = pggroup.Key.ACCOUNTING_PERIOD, amount = pggroup.Sum(x => x.Amount) };

and then return it like this

return Json(PGRow, AmountList, JsonRequestBehavior.AllowGet);

This did not work it threw an error that said The best overload match for 'System.Web.MVC.Controller.Json(object,string,System.Web.MVC.JsonRequestBehavior)' has some invalid arguments

I am completely open to all suggestions since everything I have tried has not worked; even if a suggestion takes me into a completely new direction. I honestly just need some guidance on how to go about achieving the desired result. I hope I have expressed my question clearly. Thank you all for your time and expertise, please don’t hesitate to ask for any extra code or clarification as I will be checking back as often as possible.

Update

public class Container
        {
            Array PARow;
            Array AmountList;

        }

public virtual ActionResult getAjaxPGs(string SP = null, string PG = null)
            {
                var PGList = from x in db.pg_mapping
                             where x.PG_SUB_PROGRAM == SP
                             select x;

                container.PGRow = PGList.Select(x => new { x.PG }).Distinct().ToArray();

                container.AmountList = from x in db.Spend_Web
                                    where x.PG == PG
                                    group x by new { x.ACCOUNTING_PERIOD, x.PG, x.Amount } into pggroup
                                    select new { accounting_period = pggroup.Key.ACCOUNTING_PERIOD, amount = pggroup.Sum(x => x.Amount) };


            }
  • 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-10T10:12:18+00:00Added an answer on June 10, 2026 at 10:12 am

    Create a “container” class that holds an instance of each datatype you wish to return.

    class Container
    {
        Array PGRow;
        Array AmountList;
    }
    

    Then in your code:

    Container container = new Container();
    container.PGRow = ....;
    container.AmountList = ....;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following LINQ query that returns two objects from my database. These
I'm simply trying to get data from two sql server db tables using ado.net
I'm beginning python and I'm trying to use a two-dimensional list, that I initially
I'm trying use mod_rewrite to rewrite URLs from the following: http://www.site.com/one-two-file.php to http://www.site.com/one/two/file.php The
I am trying to use 'get_posts' to pick up posts that are in two
I'm trying to use WebGrid HtmlHelper to display data from a few entities. The
I am trying to figure out if I can use LINQ to provide me
I have two tables in a LINQ to SQL dbml file. I am trying
I'm trying to use two different methods of connecting to a database to edit
I'm trying to use LINQ to return a list of ids given a list

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.