2

I'm trying to output data like this:

[[...],[...],[...],[...]]

But my query gives me this result:

[{...},{...},{...},{...}]

Here is my query:

  var result = (from c in displayedCompanies
                          group c by new { c.CodigoDeVenta } into s
                          select new{
                             ID = Convert.ToString(i++),
                             s.Key.CodigoDeVenta,
                             TotalInv = s.Sum(x => x.Inventario)
                             }).ToArray();

I've tried some options like the following but it's wrong:

  var result = (from c in displayedCompanies
                          group c by new { c.CodigoDeVenta } into s
                          select new [] {
                             ID = Convert.ToString(i++),
                             s.Key.CodigoDeVenta,
                             TotalInv = s.Sum(x => x.Inventario)
                             }).ToArray();

Note that the diference is the [] in select new []. I used to have a query before I implemented the "group by" that worked correctly, but after I added the group by this does not work anymore.

Thanks!

1
  • 1
    I would try select new List<object>(){Convert.ToString(i++),s.Key.CodigoDeVenta,s.Sum(x => x.Inventario)} Commented Feb 28, 2016 at 0:03

1 Answer 1

1

Setting aside the grouping, focusing only on the syntax, your anonymous array (new [] {...}) should be fine.

However, it appears that you're trying to assign Id = and TotalInv = which looks like a leftover from the previous revision where you were selecting an anonymous object.

So, instead, you should be able to drop the member identifiers and select just the values you want in the child arrays:

select new [] {
    Convert.ToString(i++),
    s.Key.CodigoDeVenta,
    s.Sum(x => x.Inventario)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.