none
Problema con semplice query LINQ (raggruppamento) RRS feed

  • Question

  • Salve,
    non essendo un grandissimo esperto di linq non riesco a tradurre una query che assomiglia a questa , mi potete aiutare?

    SELECT     SUM(Qta) AS SommaQta, RELGru, RELTur
    FROM         Comande
    GROUP BY RELGru, RELTur

    Grazie


    Carlo
    Tuesday, May 17, 2011 5:10 PM

Answers

  • Hola,

    Gracias por tu ayuda, pero no funciona: No agregue la cantidad

    Ciao , grazie per l'aiuto , ma la query non funziona : non somma le quantità e non aggrega su stesso gruppo e stesso turno

    Carlo


    Carlo

        I don't know what are you talking about.

        can you speak english?

        is this what you want?

     

    var query=from  c  in Comande

              group c by new{c.RELGru,c.RELTur} into g

              select new

              {

                  SommaQta=g.Sum(t=>t.Qta),

                  RELGru=g.Key.RELGru,

                  RELTur=g.Key.RELTur

               }


    Best Regards,
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Edited by Tim Tang Wednesday, May 18, 2011 11:01 AM e
    • Marked as answer by Carlik Tuesday, May 24, 2011 1:35 PM
    Wednesday, May 18, 2011 10:31 AM

All replies

  • Hola Carlos;

    Esta traducción de la consulta SQL debe ser lo que usted está buscando.

    Dim ctx = New DataContext()
    
    Dim qResults = From c in ctx.Comande
            Select sData = New With { c.RELGru, c.RELTur, c.Qta }
            Group sData By Key = New With { sData.RELGru, sData.RELTur } Into MyGroup = Group
            Select Key, MyGroup, SommaQta = MyGroup.Sum(Function(q) q.Qta)
    
    For Each rec in qResults
      Console.WriteLine(rec.Key.RELGru & " : " &rec.Key.RELTur & " : " & rec.SommaQta)
      For Each g in rec.MyGroup
        Console.WriteLine("   " & g.RELGru & " : " & g.RELTur)
      Next
    Next 

     

    Fernando

     


    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, May 18, 2011 4:47 AM
  • Hola,

    Gracias por tu ayuda, pero no funciona: No agregue la cantidad

    Ciao , grazie per l'aiuto , ma la query non funziona : non somma le quantità e non aggrega su stesso gruppo e stesso turno

    Carlo


    Carlo
    Wednesday, May 18, 2011 7:35 AM
  • Hola,

    Gracias por tu ayuda, pero no funciona: No agregue la cantidad

    Ciao , grazie per l'aiuto , ma la query non funziona : non somma le quantità e non aggrega su stesso gruppo e stesso turno

    Carlo


    Carlo

        I don't know what are you talking about.

        can you speak english?

        is this what you want?

     

    var query=from  c  in Comande

              group c by new{c.RELGru,c.RELTur} into g

              select new

              {

                  SommaQta=g.Sum(t=>t.Qta),

                  RELGru=g.Key.RELGru,

                  RELTur=g.Key.RELTur

               }


    Best Regards,
    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
    • Edited by Tim Tang Wednesday, May 18, 2011 11:01 AM e
    • Marked as answer by Carlik Tuesday, May 24, 2011 1:35 PM
    Wednesday, May 18, 2011 10:31 AM
  • Sorry I make a mistake , because , in my opinion , yesterday I wrote in Italian LINQ Forum.

    Ok , It isn't a real problem.

    Tim , I think your code is right , but now I try to translate it in VB.

    Thanks


    Carlo
    Wednesday, May 18, 2011 1:13 PM
  • Hi Carlik,

    I am writing to check the status of the issue on your side.   

    Have a nice day.

     


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Tuesday, May 24, 2011 8:48 AM
    Moderator
  • Hi Carlo,

    Thanks for your post.

    How about your issue, has it been solved? If so, please mark the useful reply as answer, or could you please sharing your answer with us?

     

    Regards,

     


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, May 24, 2011 9:18 AM
    Moderator
  • Ok , sorry , I forget to mark It as solved.

    Regards

    Thanks


    Carlo
    Tuesday, May 24, 2011 1:35 PM