user547794
user547794

Reputation: 14511

Linq to Entity Query very slow

I have a LINQ to Entity query that is running really slow. This query performs some calculation logic on a particular database and then passes the result to a ViewModel. The query was really fast until I added the 4 select statements at the bottom of the query. I need the select statements in order to return a collection of the result responses. Why is the query running so slow like this?

  var data = from SurveyResponseModel in db.SurveyResponseModels
                       group SurveyResponseModel by SurveyResponseModel.MemberId into resultCount
                       select new ResultsViewModel()
                       {

                           YesBarriersOthersResult = resultCount.Select(r => r.YesBarriersOthers),
                           NoBarriersOthersResult = resultCount.Select(r => r.NoBarriersOthers),
                           TotalResponsesResult = db.SurveyResponseModels.Count(),
                       };




            return View(data);

Upvotes: 0

Views: 790

Answers (1)

dreamerkumar
dreamerkumar

Reputation: 1550

It's hard for me to tell you what's exactly wrong here, but having faced similar problems with orms and all, I can suggest that the best way to debug the problem is to find out what sql statements are actually generated and run against the database. A lot of times your ORM could be running too many sql statements to get the same simple result.

Upvotes: 3

Related Questions