Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
T-SQL query to LINQ
Message
De
20/10/2014 19:17:21
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:
01609688
Vues:
51
>>>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)};
>
>>
>
>Ok, this compiles:
>
>var invoicesList = from invoices in _dbSet.Where(x => x.Account == accountName && x.Hidden == false)
>                               let balance = (from transact in _siriusContext.Transact where transact.InvoiceNo == invoices.InvoiceNo
>                                                  select transact).Sum(c=>c.Extension)
>                                select new InvoicesList
>                                {
>                                    InvoiceNo = invoices.InvoiceNo,
>                                    Account = invoices.Account,
>                                    Hidden = invoices.Hidden,
>                                    Descrip = invoices.Descrip1,
>                                    Created = invoices.DateTime,
>                                    Finalized = invoices.Finalized,
>                                    Balance = (decimal?)balance??0
>                                };
>
>I'll try testing it now.

why do you post a half-assed question, then change the parameters that you need later. I wasted some time figuring out a solution based on your original sample. Silly me, I should have known better..
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform