none
Sorry, I ask for more help to understand this query RRS feed

  • Question

  • Sorry, I still help to translate this query from c # in vb.net

    I'll show you where my difficulty

    This is taken from the original query tutorial Tailspin SpyWorks :

    var query = (from ProductOrders in db.OrderDetails
                           join SelectedProducts in db.Products on ProductOrders.ProductID
                           equals SelectedProducts.ProductID
                           group ProductOrders by new
                                {
                                    ProductId = SelectedProducts.ProductID,
                                    ModelName = SelectedProducts.ModelName
                                } into grp
                           select new
                               {
                                   ModelName = grp.Key.ModelName,
                                   ProductId = grp.Key.ProductId,
                                   Quantity = grp.Sum(o => o.Quantity)
                               } into orderdgrp
                           where orderdgrp.Quantity > 0
                               orderby orderdgrp.Quantity descending
                               select orderdgrp).Take(5);

    This is my translation:

    Dim query = (From ProductOrders in db.OrderDetails
                         Join SelectedProducts in db.Products On
                         ProductOrders.ProductID Equals SelectedProducts.ProductID
                         Group ProductOrders By New With
                           {
                              .ProductId = SelectedProducts.ProductID,
                              .ModelName = SelectedProducts.ModelName

                          } into grp
                          

    From this point on I can not go on, because I can not understand how to run the second Group By

    If anyone can help me

    Thanks a lot

    Fabrizio

     


    Fabrizio
    Thursday, December 30, 2010 7:52 PM

All replies

  • var query = (from ProductOrders in db.OrderDetails
    join SelectedProducts in db.Products on ProductOrders.ProductID
    equals SelectedProducts.ProductID
    group ProductOrders by new
    {
    ProductId = SelectedProducts.ProductID,
    ModelName = SelectedProducts.ModelName
    } into grp
    select new
    {
    ModelName = grp.Key.ModelName,
    ProductId = grp.Key.ProductId,
    Quantity = grp.Sum(o => o.Quantity)
    } into orderdgrp
    where orderdgrp.Quantity > 0
    orderby orderdgrp.Quantity descending
    select orderdgrp).Take(5);
    

    Hello everyone,
    I tried and tried to make this query in vb.net, but I can not.
    I do not understand if I have to use two groups, and if  so, how do I use them.
    This is a query that is in the project - tutorial Tailspin SpyWorks
    and should serve to show the 5 most popular products.
    I do not understand really how to do.

    Thaks a lot

    Fabrizio


    Fabrizio
    Wednesday, December 29, 2010 5:04 PM
  • Doesn't this work?

    http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Thursday, December 30, 2010 11:14 AM
  • var query = (from ProductOrders in db.OrderDetails
    join SelectedProducts in db.Products on ProductOrders.ProductID
    equals SelectedProducts.ProductID
    group ProductOrders by new
    {
    ProductId = SelectedProducts.ProductID,
    ModelName = SelectedProducts.ModelName
    } into grp
    select new
    {
    ModelName = grp.Key.ModelName,
    ProductId = grp.Key.ProductId,
    Quantity = grp.Sum(o => o.Quantity)
    } into orderdgrp
    where orderdgrp.Quantity > 0
    orderby orderdgrp.Quantity descending
    select orderdgrp).Take(5);
    
    

    Hello,

    first of all thank you for your reply , but I tried several times but the result does not work

    I would try to do the translation , then please could you give me what is wrong and how can I fix it ?

     


    Fabrizio

     

    Dim query = (From ProductOrders in db.OrderDetails
       Join SelectedProducts in db.Products On 
       ProductOrders.ProductID Equals SelectedProducts.ProductID
       Group ProductOrders By New With<br/>
         {<br/>
          .ProductId = SelectedProducts.ProductID,
          .ModelName = SelectedProducts.ModelName
    } into grp

    From now on I can not understand how I do and I can not find Tutorial governance or someone to help me Please would you be
    so kind to give me a hand 
    Thanks a lot
    Fabrizio
    
    

    Thursday, December 30, 2010 3:39 PM