I am trying to learn a bit about latest ASP.NET MVC 6 and I have a super basic controller which does a linq query that is taking several minutes to complete...
The method I have in the controller is something like this:
public IActionResult GetSampleData(string date)
{
string[] date = date.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
int month = Convert.ToInt32(date[0]);
int day = Convert.ToInt32(date[1]);
int year = Convert.ToInt32(date[2]);
var results =
(from c in db.Book
where c.Author.Equals("abc")
&& (c.Created.CompareTo(new DateTime(year, month, day, 0, 0, 0)) >= 0)
&& (c.Created.CompareTo(new DateTime(year, month, day, 23, 59, 59)) < 0)
select new ObjectExample
{
Property1 = c.Field1,
Property2 = c.Field2,
Property3 = c.Field3,
Property4 = c.Field4,
Property5 = c.Field5,
});
return View(results.ToList());
}
Well... that method is either extremely slow (takes more than 5 minutes to complete) or it ends up on a Gateway issue like this:
HTTP Error 502.3 - Bad Gateway
The specified CGI application encountered an error and the server terminated the process
Detailed Error Information:
Module httpPlatformHandler
Notification ExecuteRequestHandler
Handler httpPlatformHandler
Error Code 0x80072ee2
If I run the exact same query but on the SQL Server, it doesn't even take a second to complete... the results are just 7 entries.
What am I missing here? This code is the exact same code that I have on another ASP.NET web application (the other one is using Silverlight) and it works super fast.
Is there anything that I am missing I should take a look at? Also, any recommendations for debugging this? (although it is pretty straight forward...)
Finally, this is my appsettings.json that contains the connection string
{
"Data": {
"DefaultConnection": {
"ConnectionString": "Data Source=DataBaseServerSample01;Initial Catalog=SampleDB;Integrated Security=True;App=EntityFramework"
}
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Verbose",
"System": "Information",
"Microsoft": "Information"
}
}
}
Note. I am using ASP.NET MVC6 RC (Update 1) and I created the model and the controller using the scaffolding through the command line.
Thanks!