Imas par nacina, najkraci i najvise u duhu L2S-a je:
Code:
var xx = from i in db.Icecreams
select new { i.Name, suma = i.Bills.Sum(b => b.Quantum) };
sto generise sledeci SQL upit:
Code:
SELECT [t0].[Name], (
SELECT SUM([t1].[Quantum])
FROM [dbo].[Bill] AS [t1]
WHERE [t1].[IcecreamId] = [t0].[IcecreamID]
) AS [suma]
FROM [dbo].[Icecream] AS [t0]
Ako bas hoces da forsiras inner join i da dobijes SQL upit kakav si naveo, onda je oblik sledeci (s tim sto se krece od tebele koja se sumira):
Code:
var xx = from b in db.Bills
group b by b.Icecream.Name into gb
select new { Name = gb.Key, suma = gb.Sum(a => a.Quantum) };
sto generise sledeci skript
Code:
SELECT SUM([t0].[Quantum]) AS [suma], [t1].[Name]
FROM [dbo].[Bill] AS [t0]
INNER JOIN [dbo].[Icecream] AS [t1] ON [t1].[IcecreamID] = [t0].[IcecreamId]
GROUP BY [t1].[Name]
U oba slucaja ces dobiti isti rezultat (mozda drugacije sortiran posto nemas orderby a ova dva primera koriste razlicite tabele kao polazne)
▪ The word 'politics' is derived from the word 'poly', meaning 'many', and the word 'ticks', meaning 'blood sucking parasites' - Larry Hardiman
▪ If the good guy gets the girl, it's rated PG; if the bad guy gets the girl, it's rated R; and if everybody gets the girl, it's rated X
▪ Illegal aliens have always been a problem in the United States. Ask any Native American