scott lafoy
scott lafoy

Reputation: 1013

Entity Framework DBContext.Entry() is very slow

I am trying to get some data out of the database. Using the .Entry is very slow, over 65% of time spent is right there. Does anyone have any ideas how to optimize my query? I only want to get the data as read only.

enter image description here

Sorry about adding the code as an image, but it would not let me post the question when it was formatted using the code sample button.

Upvotes: 0

Views: 1064

Answers (1)

Alexandre Severino
Alexandre Severino

Reputation: 1613

Your query is definitively far from being optimized. Try this instead:

seismic2DSurvey.EndsAndBends = winPicsDbContext.Locations
    .Where(t => t.surveyId = seismic2DSurvey.Id && (t.IsBend || (t.IsEnd.HasValue && t.IsEnd.Value))).OrderBy(t => t.TraceNumber).ToList();

seismic2DSurvey.TraceCount = locations.Count();
seismic2DSurvey.SurveyLocations = null;

Upvotes: 1

Related Questions