Solved

LINQ query time out

Posted on 2013-06-03
4
353 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 62

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 62

Expert Comment

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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now