tags:

views:

36

answers:

2

Hi ALL, I have data like this

productid  cost
prant      6.70
prant       0
prant       7.0
gant        8.7
gant        0.1
gant        4.5

how can i flatten them into one result as "prant 13.70 gant 13.3" in Linq To sql

My linq query gives me two rows

Results:

prant 13.7
gant  13.3

Query:

from c in test
group new {c}
by new {
    c.productid
} into g
select new
{
    ProductIdandAmount = g.Key.productid +  g.Sum(p => p.c.cost)
};

can someone help me out

Thanks

A: 

You've implement map, now you need to implement reduce:

var query = from c in test ...

var summary = string.Join(" ", query.ToArray());
Frank Krueger
A: 

Error:The best overloaded method match for 'string.Join(string, string[])' has some invalid arguments,

Argument '2': cannot convert from 'AnonymousType#1[]' to 'string[]' i tried the code you gave me give me two errors....