Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
T-SQL query to LINQ
Message
 
 
To
20/10/2014 15:21:23
John Baird
Coatesville, Pennsylvania, United States
General information
Forum:
ASP.NET
Category:
LINQ
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01609660
Message ID:
01609678
Views:
39
>>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
Previous
Reply
Map
View

Click here to load this message in the networking platform