Solved

LINQ query time out

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

11 Experts available now in Live!

Get 1:1 Help Now