Solved

LINQ query time out

Posted on 2013-06-03
4
369 Views
Last Modified: 2013-06-04
can any one help me and tell me why this linq query take long time ?
 _objDashBoardInfoLst = (from s in _objCashCollectionEntity.Transactions
                                    where (s.Transaction_Status == "0" || s.Transaction_Status == "1") && (s.Transaction_DateTime >= _datetimeFromdate.Date && s.Transaction_DateTime <= _datetimeTodate.Date)

                                    group s by s.Transaction_DateTime.Value.Month into grouping
                                    select new
                                    {
                                        _datetimeDate = grouping.Select(s => s.Transaction_DateTime.Value).FirstOrDefault(),
                                        _doubleTransactionsAmount = grouping.Select(s => s.Transaction_TotalValue).Sum(),
                                        _doubleTransactionsFees = grouping.Select(s => s.Transaction_TotalFees).Sum(),
                                        _intTransactionsCount = (grouping.Select(s => s.Transaction_ID).Count()),
                                        _intPostOfficesCount = (grouping.Select(s => s.FK_PostOfficeID).Distinct().Count()),
                                    }).AsEnumerable().Select(item => new DashBoardInfo
                                 {
                                     Date = item._datetimeDate,
                                     TransactionsAmount = (decimal)item._doubleTransactionsAmount,
                                     TransactionsFees = (decimal)item._doubleTransactionsFees,
                                     PostOfficesCount = item._intPostOfficesCount,
                                     TransactionsCount = item._intTransactionsCount,
                                 }).ToList();

Open in new window

any way to enhance it ?
thnx
0
Comment
Question by:AhmedHindy
  • 2
4 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39216718
Whats the size of the collection?
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39217339
Hi AhmedHindy;

Would not this bering back the same results in less time?

 _objDashBoardInfoLst = (from s in _objCashCollectionEntity.Transactions
                         where (s.Transaction_Status == "0" || s.Transaction_Status == "1") && (s.Transaction_DateTime >= _datetimeFromdate.Date && s.Transaction_DateTime <= _datetimeTodate.Date)
                         group s by s.Transaction_DateTime.Value.Month into grouping
                         select new DashBoardInfo
                         {
                             Date = grouping.Select(s => s.Transaction_DateTime.Value).FirstOrDefault(),
                             TransactionsAmount = grouping.Select(s => s.Transaction_TotalValue).Sum(),
                             TransactionsFees = grouping.Select(s => s.Transaction_TotalFees).Sum(),
                             PostOfficesCount = (grouping.Select(s => s.Transaction_ID).Count()),
                             TransactionsCount = (grouping.Select(s => s.FK_PostOfficeID).Distinct().Count()),
                         }).ToList();

Open in new window

0
 
LVL 4

Author Closing Comment

by:AhmedHindy
ID: 39218688
it worked
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39218837
Glad to hear that worked out for you. Have a great day.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question