Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
T-SQL query to LINQ
Message
 
To
20/10/2014 19:17:21
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:
01609695
Views:
59
Naomi just prefers that you do the work for her, hehe...

+++ Rick ---

>>>>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..
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform