Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C# LINQ Problem

Empfohlene Antworten

Veröffentlicht

Halöle,

ich beschäftige mich seit kurzem erst Linq und ich tue mich irgendwie schwer mit Aggregatfunktionen..

Ich versuche folgenden SQL-Query nach Linq umzuformen.

 

Select ProductTitle, Sku, Count (*) As Count


FROM Product AS P 

Inner JOIN AssignedProduct AS A on P.Id = A.ProductId

Inner JOIN LineItem AS L on L.AssignedProductId = A.Id 

INNER JOIN Orders AS O on O.Id = L.OrderId

INNER JOIN Customer AS C on C.Id = O.CustomerId 


where PerformanceDate Between '01.01.2012' and '25.09.2012'



group by ProductTitle,Sku

der Query gibt als Ergebnis den Produkttitel, die Sku des Produkts und die Häufigkeit der jeweiligen Sku aus..:) In Linq sieht das bei mir bisher so aus :
 

from element in DataLayer.RepositoryDistributor.LineItemRepository.DataSource

                               where element.Orders.PerformanceDate > VonSelector.SelectedDate //Startdatum

                               where element.Orders.PerformanceDate < StopDate.SelectedDate    //Enddatum


//LineItem.AssignedProduct.Product.Sku 


                               select element;

Weiss jemand wie man die Skunummern aufsummieren bzw. gruppieren kann ?

Weil ich mich immer schwer tue, wenn ich die Stuktur der DB etc. nicht sehe...

...einfach mal 3 Links, die dir evtl. weiterhelfen.

Group Elements in a Sequence

Gewusst wie: Schreiben von LINQ-Abfragen in C#

101 LINQ Samples in C#

hoffe es hilft - happy kanobeln wünsch ich dir.

*Nachtrag: Empfehlen kann ich dir auch das Buch Datenbankprogrammierung mit Visual C# 2010 aus dem Hause MicrosoftPress. ISBN: 978-3-86645-446-0 Gibts bei Amazon für, momentan, ab ca. 35 Euro gebraucht. Ist aber eine gute Investition.

Bearbeitet von mcn

...? Ich möcht nicht unhöflich sein, aber da täte mich jetzt ein Beispiel interessieren, wo das

[...] so in LINQ übertragbar...[...]
ist.

Weil, wenn es kein Problem ist...

mfg


var selection = from p in product
join a in assignedProduct on p.ProductId equals a.ProductID
join l in lineItem on a.AssignedProductID equals l.AssignedProductID
join o in order on l.OrderID equals o.OrderId
join c in customer on o.CustomerId equals c.CustomerId
select new
{
p.ProductTitle // whatever ...
};
[/php]

So in etwa ist das Grundgerüst ...

Was ich nicht habe, ist das Performance-Date, das GroupBy und das (count) sku.

Auf die Schnelle habe ich da keinen Zusammenhang herstellen können, wo was hinkommt. Die Domäne ist mir nicht weiter bekannt *g*

Zusammen mit dem TO kann man sich das auch sicher erschließen ...

Ansonsten geht es hiermit weiter:

LINQ - Grouping Operators "Nested Grouping"

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.