2016-07-14 2 views
1
finden
var CartItemsGroup = (from Cart in db.BuyOnlineCartMasters // orderby this Cart.CartID descending 
    join CartDetails in db.BuyOnlineCartDetails 
     on Cart.CartID equals CartDetails.CartID 

    join ProductMaster in db.tblBuyOnlineMasters.Where(x => x.CompanyID == CompanyID) 
     on CartDetails.BuyOnlineID equals ProductMaster.BuyOnlineID 

//I tried here did not work , orderby Cart.CartID descending 

    select new { Cart.CartID, Cart.InvoiceNumber, ProductMaster.CompanyID, 
    ProductMaster.Price, ProductMaster.Title, ProductMaster.OfferPrice, 
    CartDetails.SoldPrice, CartDetails.Qty, CartDetails.ShippingStatus, 
    CartDetails.DeliveryStatus, TotalAmt = (CartDetails.Qty * CartDetails.SoldPrice)} 

    into x 

//I tried here did not work, orderby x.CartID descending 

//TODO: where conditions are not set for cart like payment paid etc 
    group x by x.CartID) 
    .ToList(); 

Ich möchte von der cartId das Ergebnis bestellen, weil der groupby Klausel ich nicht in der Lage bin, um esLinq mehrere beitreten, dann GroupBy zusammen mit OrderBy, versuchte alles, konnte ich

Screenshot of the output structure

getan

Antwort

1

Die Bestellung muss nach Gruppierung sein.

Ihr Ziel zu erreichen, ersetzen

group x by x.CartID 

mit

group x by x.CartID into g 
orderby g.Key descending 
select g 
+0

Wow, wie ein Charme, dank Mann –

+0

wie auf einer anderen Spalte tun orderby, nur für den Fall für eine Referenz –

+0

Es hängt davon ab, ob Sie die Gruppen oder Gruppenelemente bestellen möchten. Die Reihenfolge der Gruppen nach Spalten, die nicht Teil des Schlüssels sind, ist nicht einfach. –

1

zunächst Ihre Daten und wählen Sie dann Gruppe. Das wird funktionieren. Eine Probe mit meinen Tabellen

from data in 
    (from o in DB.GM_ORDER 
     join g in DB.GM_ORDERITEMS on o.ORDERID equals g.ORDERID 
     join i in DB.GM_ITEM on g.ITEMID equals i.ITEMID 
    where o.ORDERID<=11160 /* or any other filter to be applied */ 
    orderby o.ORDERID descending, i.ITEMCODE ascending /* in your case ORDERID will be CARTID. Continue sorting within the ORDER/CART with a second parameter (in your case can be delivery status) */ 
    select new { o.ORDERID, i.ITEMCODE, g.ITEMID, Total = (g.CURR_PRICE * g.QTY) } 
) select data 
into x 
group x by x.ORDERID 
+0

Ich hoffe, dass dies funktioniert, ich habe die oben genannten, danke für die Unterstützung –

+1

schätzen Sie Ihren Kommentar @arunprasad – HGMamaci

+0

Dieser Trick funktioniert in LINQ zu Objekten, aber nicht in anderen LINQ-Anbietern wie LINQ zu Entities. –