none
LINQ TO SQL problem RRS feed

  • Question

  • Hi all,

    I had this question in the general linq area...i am moving it Linq to sql
    I have the following data

    ProductId Description cost
    12  test           0.0
    12  test 8.8
    12 test 7.9
    27 asdf 9.0
    27  asdf 2.0
    27 asdf 2.0

    I want the following result

    12  test 0.0 / test8.8/test 7.9
    27  asdf 9.0/asdf 2.0/ asdf 2.0
      

    so far i could only come up with this ..can someone point me in the right direction

    Thank you so much

    var n = from c in query
                 group new {c}
                 by new
                 {
                       c.prodid,
                       c.cost,
                       c.prodcode1
                  }
                  into g
                                  
                  select new{
                                        g.Key.prodid,
                                        Products=(g.Key.Description) +        g.Key.cost.ToString()),
                                     };

    Tuesday, September 15, 2009 9:02 PM

Answers

  • Hi smithani1,

    For this case, we do not suggest that you get the final result with Linq as the point of this problem lies in the rearrangement of the table fields, instead of querying itself. So we suggest that you load the data you need from the DataContext with simple Linq statement and then do the modification with Linq to object in memory to get the final result you want.


    Best regards,
    Charlie Lee

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Zhipeng Lee Tuesday, September 22, 2009 1:59 AM
    Monday, September 21, 2009 3:56 AM