Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
T-SQL query to LINQ
Message
 
 
À
20/10/2014 15:21:23
John Baird
Coatesville, Pennsylvanie, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01609660
Message ID:
01609678
Vues:
38
>>I got as far as
>>
>>
>> var invoicesList = (from invoices in _dbSet.Where(x => x.Account == accountName && x.Hidden == false)
>>                                join transact in _siriusContext.Transact on invoices.InvoiceNo equals transact.InvoiceNo into InvoiceBalance
>>                                from rt in InvoiceBalance.DefaultIfEmpty()
>>                                select new InvoicesList
>>                                {
>>                                    InvoiceNo = invoices.InvoiceNo,
>>                                    Account = invoices.Account,
>>                                    Hidden = invoices.Hidden,
>>                                    Descrip = invoices.Descrip1,
>>                                    Created = invoices.DateTime,
>>                                    Finalized = invoices.Finalized,
>>                                    Balance = (decimal?)rt.Extension??0
>>                                });
>>
>>but this is still not what I want as I want sum of extension. Still struggling.
>
>
>      var l = from inv in invoice
>                        join ib in invoiceBalance on inv.id equals ib.id
>                        group ib by inv.id into g
>                        select new {InvoiceId = g.Key, Balance = g.Sum(s=>s.balance)};

>
I was thinking about this syntax, but my case is more complex as I want lots of columns from the parent table, not just one InvoiceNo column.

That's the reason the original query was written as a subquery (so we don't need to group on every column from the parent table).
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform