Reputation: 959
My Entity Framework generic repository project using SQL Server is too slow. How can I improve my project?
These queries are getting data in 30 seconds. I have 1000 items in Answers
table and 300 rows in the Questions
table
List<QuestionVM> questionList = questionServices.GetAll()
.Where(x => x.SubCategory_Id == id)
.ToList();
List<AnswerVM> answersList = answerServices.GetAll()
.Where(x => x.SubCat_Id == id)
.ToList();
And this is my GetAll
function
public IEnumerable<QuestionVM> GetAll()
{
var data = ProjectMapper.ConvertToVMList<IEnumerable<QuestionVM>>(_QuestionRepository.GetAll());
return (IEnumerable<QuestionVM>)data;
}
Upvotes: 0
Views: 173
Reputation: 88852
How can i improve my project?
One easy way is throw away your custom repository and use the DbContext directly.
You're returning all the rows from the database and filtering them on the client. You need to filter the DbSet in your DbContext and then copy the data into your ViewModel.
Upvotes: 3