C# WPF Linq Slow Query [on hold]











up vote
0
down vote

favorite












public List<borrower> DefaultAndPageinate(int pageNumber = 1, string isSearched = "")
{
int numberOfObjectsPerPage = 13;
string nameOfUser = ControlCenter.TitleCase(searchUser.Text);

var queryResultPage = LoanConfiguration._database.borrowers.ToList();
if (pageNumber == 1 && searchUser.Text == "")
queryResultPage = queryResultPage.Take(numberOfObjectsPerPage).ToList();
else if (pageNumber == 1 && searchUser.Text != "")
{


var list = LoanConfiguration._database.borrowers.ToList();
var nameList = queryResultPage.Where(a => a.first_name.Contains(nameOfUser) || a.middle_name.Contains(nameOfUser)
|| a.last_name.Contains(nameOfUser) || a.borrowers_id.Contains(nameOfUser));
numberOfSearchResult = nameList.Count();
queryResultPage = nameList.Take(numberOfObjectsPerPage).ToList();



}
else if (searchUser.Text != "")
{

var nameList = queryResultPage.Where(a => a.first_name.Contains(nameOfUser) || a.middle_name.Contains(nameOfUser)
|| a.last_name.Contains(nameOfUser) || a.borrowers_id.Contains(nameOfUser));
numberOfSearchResult = nameList.Count();
--pageNumber;

queryResultPage = nameList.Skip(numberOfObjectsPerPage * pageNumber)
.Take(numberOfObjectsPerPage).ToList();
}
else
{
--pageNumber;
queryResultPage = queryResultPage
.Skip(numberOfObjectsPerPage * pageNumber)
.Take(numberOfObjectsPerPage).ToList();
}

return queryResultPage.ToList();
}


This is the next and previous class



private void nextPage(object sender, RoutedEventArgs e)
{
int getCurrentPage = int.Parse(currentPage.Text);

if (searchUser.Text != "")
{

if (numberOfSearchResult != 0)
{
getNumberOfFields = numberOfSearchResult;
}

}
double ax = (getNumberOfFields / 13.0);
if (getCurrentPage < Math.Ceiling(ax))
{
getCurrentPage++;
currentPage.Text = getCurrentPage.ToString();
dataGrid.ItemsSource = DefaultAndPageinate(getCurrentPage, searchUser.Text);
}
}

private void prevPage(object sender, RoutedEventArgs e)
{
int getCurrentPage = int.Parse(currentPage.Text);
if (getCurrentPage > 1)
{
getCurrentPage--;
currentPage.Text = getCurrentPage.ToString();
dataGrid.ItemsSource = DefaultAndPageinate(getCurrentPage, searchUser.Text);
}
}


Hello guys so what I am creating here is a pagination on a specific table in my database. It runs fine but the selection execute is too terrible and slow. I tried searching for some optimization for selection but I didn't find any. Also I'm getting a 9500 thread in the diagnostic and I'm getting two instances of selection everytime I click next.










share|improve this question







New contributor




Rongiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by t3chb0t, πάντα ῥεῖ, VisualMelon, vnp, tinstaafl yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – t3chb0t, πάντα ῥεῖ, VisualMelon, vnp, tinstaafl

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2




    I'm getting two instances of selection everytime I click next. - this doesn't sound like your solution is ready for Code Review because we're not fixing bugs here.
    – t3chb0t
    yesterday















up vote
0
down vote

favorite












public List<borrower> DefaultAndPageinate(int pageNumber = 1, string isSearched = "")
{
int numberOfObjectsPerPage = 13;
string nameOfUser = ControlCenter.TitleCase(searchUser.Text);

var queryResultPage = LoanConfiguration._database.borrowers.ToList();
if (pageNumber == 1 && searchUser.Text == "")
queryResultPage = queryResultPage.Take(numberOfObjectsPerPage).ToList();
else if (pageNumber == 1 && searchUser.Text != "")
{


var list = LoanConfiguration._database.borrowers.ToList();
var nameList = queryResultPage.Where(a => a.first_name.Contains(nameOfUser) || a.middle_name.Contains(nameOfUser)
|| a.last_name.Contains(nameOfUser) || a.borrowers_id.Contains(nameOfUser));
numberOfSearchResult = nameList.Count();
queryResultPage = nameList.Take(numberOfObjectsPerPage).ToList();



}
else if (searchUser.Text != "")
{

var nameList = queryResultPage.Where(a => a.first_name.Contains(nameOfUser) || a.middle_name.Contains(nameOfUser)
|| a.last_name.Contains(nameOfUser) || a.borrowers_id.Contains(nameOfUser));
numberOfSearchResult = nameList.Count();
--pageNumber;

queryResultPage = nameList.Skip(numberOfObjectsPerPage * pageNumber)
.Take(numberOfObjectsPerPage).ToList();
}
else
{
--pageNumber;
queryResultPage = queryResultPage
.Skip(numberOfObjectsPerPage * pageNumber)
.Take(numberOfObjectsPerPage).ToList();
}

return queryResultPage.ToList();
}


This is the next and previous class



private void nextPage(object sender, RoutedEventArgs e)
{
int getCurrentPage = int.Parse(currentPage.Text);

if (searchUser.Text != "")
{

if (numberOfSearchResult != 0)
{
getNumberOfFields = numberOfSearchResult;
}

}
double ax = (getNumberOfFields / 13.0);
if (getCurrentPage < Math.Ceiling(ax))
{
getCurrentPage++;
currentPage.Text = getCurrentPage.ToString();
dataGrid.ItemsSource = DefaultAndPageinate(getCurrentPage, searchUser.Text);
}
}

private void prevPage(object sender, RoutedEventArgs e)
{
int getCurrentPage = int.Parse(currentPage.Text);
if (getCurrentPage > 1)
{
getCurrentPage--;
currentPage.Text = getCurrentPage.ToString();
dataGrid.ItemsSource = DefaultAndPageinate(getCurrentPage, searchUser.Text);
}
}


Hello guys so what I am creating here is a pagination on a specific table in my database. It runs fine but the selection execute is too terrible and slow. I tried searching for some optimization for selection but I didn't find any. Also I'm getting a 9500 thread in the diagnostic and I'm getting two instances of selection everytime I click next.










share|improve this question







New contributor




Rongiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by t3chb0t, πάντα ῥεῖ, VisualMelon, vnp, tinstaafl yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – t3chb0t, πάντα ῥεῖ, VisualMelon, vnp, tinstaafl

If this question can be reworded to fit the rules in the help center, please edit the question.









  • 2




    I'm getting two instances of selection everytime I click next. - this doesn't sound like your solution is ready for Code Review because we're not fixing bugs here.
    – t3chb0t
    yesterday













up vote
0
down vote

favorite









up vote
0
down vote

favorite











public List<borrower> DefaultAndPageinate(int pageNumber = 1, string isSearched = "")
{
int numberOfObjectsPerPage = 13;
string nameOfUser = ControlCenter.TitleCase(searchUser.Text);

var queryResultPage = LoanConfiguration._database.borrowers.ToList();
if (pageNumber == 1 && searchUser.Text == "")
queryResultPage = queryResultPage.Take(numberOfObjectsPerPage).ToList();
else if (pageNumber == 1 && searchUser.Text != "")
{


var list = LoanConfiguration._database.borrowers.ToList();
var nameList = queryResultPage.Where(a => a.first_name.Contains(nameOfUser) || a.middle_name.Contains(nameOfUser)
|| a.last_name.Contains(nameOfUser) || a.borrowers_id.Contains(nameOfUser));
numberOfSearchResult = nameList.Count();
queryResultPage = nameList.Take(numberOfObjectsPerPage).ToList();



}
else if (searchUser.Text != "")
{

var nameList = queryResultPage.Where(a => a.first_name.Contains(nameOfUser) || a.middle_name.Contains(nameOfUser)
|| a.last_name.Contains(nameOfUser) || a.borrowers_id.Contains(nameOfUser));
numberOfSearchResult = nameList.Count();
--pageNumber;

queryResultPage = nameList.Skip(numberOfObjectsPerPage * pageNumber)
.Take(numberOfObjectsPerPage).ToList();
}
else
{
--pageNumber;
queryResultPage = queryResultPage
.Skip(numberOfObjectsPerPage * pageNumber)
.Take(numberOfObjectsPerPage).ToList();
}

return queryResultPage.ToList();
}


This is the next and previous class



private void nextPage(object sender, RoutedEventArgs e)
{
int getCurrentPage = int.Parse(currentPage.Text);

if (searchUser.Text != "")
{

if (numberOfSearchResult != 0)
{
getNumberOfFields = numberOfSearchResult;
}

}
double ax = (getNumberOfFields / 13.0);
if (getCurrentPage < Math.Ceiling(ax))
{
getCurrentPage++;
currentPage.Text = getCurrentPage.ToString();
dataGrid.ItemsSource = DefaultAndPageinate(getCurrentPage, searchUser.Text);
}
}

private void prevPage(object sender, RoutedEventArgs e)
{
int getCurrentPage = int.Parse(currentPage.Text);
if (getCurrentPage > 1)
{
getCurrentPage--;
currentPage.Text = getCurrentPage.ToString();
dataGrid.ItemsSource = DefaultAndPageinate(getCurrentPage, searchUser.Text);
}
}


Hello guys so what I am creating here is a pagination on a specific table in my database. It runs fine but the selection execute is too terrible and slow. I tried searching for some optimization for selection but I didn't find any. Also I'm getting a 9500 thread in the diagnostic and I'm getting two instances of selection everytime I click next.










share|improve this question







New contributor




Rongiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











public List<borrower> DefaultAndPageinate(int pageNumber = 1, string isSearched = "")
{
int numberOfObjectsPerPage = 13;
string nameOfUser = ControlCenter.TitleCase(searchUser.Text);

var queryResultPage = LoanConfiguration._database.borrowers.ToList();
if (pageNumber == 1 && searchUser.Text == "")
queryResultPage = queryResultPage.Take(numberOfObjectsPerPage).ToList();
else if (pageNumber == 1 && searchUser.Text != "")
{


var list = LoanConfiguration._database.borrowers.ToList();
var nameList = queryResultPage.Where(a => a.first_name.Contains(nameOfUser) || a.middle_name.Contains(nameOfUser)
|| a.last_name.Contains(nameOfUser) || a.borrowers_id.Contains(nameOfUser));
numberOfSearchResult = nameList.Count();
queryResultPage = nameList.Take(numberOfObjectsPerPage).ToList();



}
else if (searchUser.Text != "")
{

var nameList = queryResultPage.Where(a => a.first_name.Contains(nameOfUser) || a.middle_name.Contains(nameOfUser)
|| a.last_name.Contains(nameOfUser) || a.borrowers_id.Contains(nameOfUser));
numberOfSearchResult = nameList.Count();
--pageNumber;

queryResultPage = nameList.Skip(numberOfObjectsPerPage * pageNumber)
.Take(numberOfObjectsPerPage).ToList();
}
else
{
--pageNumber;
queryResultPage = queryResultPage
.Skip(numberOfObjectsPerPage * pageNumber)
.Take(numberOfObjectsPerPage).ToList();
}

return queryResultPage.ToList();
}


This is the next and previous class



private void nextPage(object sender, RoutedEventArgs e)
{
int getCurrentPage = int.Parse(currentPage.Text);

if (searchUser.Text != "")
{

if (numberOfSearchResult != 0)
{
getNumberOfFields = numberOfSearchResult;
}

}
double ax = (getNumberOfFields / 13.0);
if (getCurrentPage < Math.Ceiling(ax))
{
getCurrentPage++;
currentPage.Text = getCurrentPage.ToString();
dataGrid.ItemsSource = DefaultAndPageinate(getCurrentPage, searchUser.Text);
}
}

private void prevPage(object sender, RoutedEventArgs e)
{
int getCurrentPage = int.Parse(currentPage.Text);
if (getCurrentPage > 1)
{
getCurrentPage--;
currentPage.Text = getCurrentPage.ToString();
dataGrid.ItemsSource = DefaultAndPageinate(getCurrentPage, searchUser.Text);
}
}


Hello guys so what I am creating here is a pagination on a specific table in my database. It runs fine but the selection execute is too terrible and slow. I tried searching for some optimization for selection but I didn't find any. Also I'm getting a 9500 thread in the diagnostic and I'm getting two instances of selection everytime I click next.







c# wpf






share|improve this question







New contributor




Rongiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Rongiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Rongiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









Rongiro

1




1




New contributor




Rongiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Rongiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Rongiro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by t3chb0t, πάντα ῥεῖ, VisualMelon, vnp, tinstaafl yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – t3chb0t, πάντα ῥεῖ, VisualMelon, vnp, tinstaafl

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by t3chb0t, πάντα ῥεῖ, VisualMelon, vnp, tinstaafl yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – t3chb0t, πάντα ῥεῖ, VisualMelon, vnp, tinstaafl

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 2




    I'm getting two instances of selection everytime I click next. - this doesn't sound like your solution is ready for Code Review because we're not fixing bugs here.
    – t3chb0t
    yesterday














  • 2




    I'm getting two instances of selection everytime I click next. - this doesn't sound like your solution is ready for Code Review because we're not fixing bugs here.
    – t3chb0t
    yesterday








2




2




I'm getting two instances of selection everytime I click next. - this doesn't sound like your solution is ready for Code Review because we're not fixing bugs here.
– t3chb0t
yesterday




I'm getting two instances of selection everytime I click next. - this doesn't sound like your solution is ready for Code Review because we're not fixing bugs here.
– t3chb0t
yesterday















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Quarter-circle Tiles

build a pushdown automaton that recognizes the reverse language of a given pushdown automaton?

Mont Emei