Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
T-SQL query to LINQ
Message
 
 
To
20/10/2014 14:18:29
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:
01609671
Views:
40
>>>>>>>Off the top of my head, if I understood your problem correctly. It would be something like this:
>>>>>>>
>>>>>>>var list = (from  d in _dbSet.Where(x => x.Account == accountName && x.Hidden == false)
>>>>>>>               from t in transact .Sum(s=>s.extension).Where(w=>w.extension != null && w.invoiceNo == d.InvoiceNo).
>>>>>>>              select(x => new InvoicesList { InvoiceNo = x.InvoiceNo, Account = x.Account, Hidden = x.Hidden, 
>>>>>>>                                                          Descrip = x.Descrip1, Finalized = x.Finalized, Created = .DateTime}, InvoiceBalance= t)).ToList();
>>>>>>>
>
>
>
>            var list = new List<decimal?> {2.5M, null, 2.5M, 5M};
>            var s = list.Sum();
>
>
>this returns 10 as the sum which is correct. it is ignoring the nulls... so try this
>
>
>var list = (from  d in _dbSet.Where(x => x.Account == accountName && x.Hidden == false)
>               from t in transact .Sum(s=>s.extension).Where(w => w.invoiceNo == d.InvoiceNo).
>               select(x => new InvoicesList { InvoiceNo = x.InvoiceNo, Account = x.Account, Hidden = x.Hidden, 
>                                                               Descrip = x.Descrip1, Finalized = x.Finalized, Created = .DateTime}, InvoiceBalance= t)).ToList();
>
The problem is not the NULL, the problem is that you can not use Sum(s=>s.extension) and then Where as after you get sum, it just creates decimal. If I try to swap where and SUM I get other errors.

So, I am not getting the syntax to work :(
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