Why Doesn't Microsoft's Contoso Crafts Demo Work in the Real World?

PostAlmostAnything 1 Reputation point
2021-10-27T17:58:08.293+00:00

Micorsoft suckered me into using ASP.Net Core for my latest website with a demo they call Contoso Crafts complete with videos where Scott Hanselman keeps claiming to be showing people how easy it is to build an ASP.Net Core web application. Problem, he gets all his data at once and if your app ends up with too much data it stops loading. On top of that he doesn't even use a database, so right there everyone working in the real word cannot copy his design exactly. I am now learning this the hard way because every few hours my app stops loading on pages that need post data which uses a task to get all posts.

Since this is clearly a problem of Microsoft's creation I am asking that a Microsoft staff member respond to this question with an example of how someone could use Contoso Crafts with a database in the real world without getting all data at once. They should ideally create a database with at least 10,000 test rows and build an example of how someone could use ASP.Net Core to build an efficient app in the real world.

I've tried giving my app more time to process stuff by adding sqlServerOptions => sqlServerOptions.CommandTimeout(160).EnableRetryOnFailure()); to my Startup.cs file. I also gave the app more max memory in IIS, but it doesn't even seem to try using the additional resources. I also started caching the results of my get all method so that it only had to run once an hour unless a user add or edits anything.

Sample code is available in a previous post which nobody at Microsoft has answered and the only responses I've gotten at all are vague recommendations not to use ToArray() or to use EnableRetryOnFailure() (see https://learn.microsoft.com/en-us/answers/questions/601858/aspnet-core-app-only-works-for-few-minutes-after-r.html). Then I posted something on StackOverflow which has gotten a response which looks really good (see https://stackoverflow.com/questions/69730340/does-ef-core-have-a-query-que/69732526). That guy is recommending using somethings called an IQueryable and a ViewModel. Those are both new concepts for me because I was not able to build anything new for about 7 years (2012 - 2019) and when I did get back into the game nobody was using WebForms anymore.

Right now I am wondering how to keep my query form crashing my site in the meantime until I fix it. It seems like giving the app more resources doesn't work because it doesn't bother trying to use the new resources. I am wondering if Microsoft has any limits built into .Net Core which would cause an app to crash instead of using all possible CPU and RAM.

I'm leaving town until tomorrow night and if I don't see an answer from a Microsoft employee that solves my problem when I get back I will go on a tyraid around the internet that will persuade people to never bother using ASP.Net Core as long as PHP exists.
UPDATE: Less than an hour after restarting my app and it won't load. My CPU and RAM are well within limits. Is there a maximum constraint in EF Core or .Net Core which limits the size that a query can be? That is the only explanation I can think of other than there being too many requests and a bottleneck somewhere

Also, is there a way I could use SSMS to speed things up on the database side? Like giving a specific database higher priority or making sure that it uses all available resources?

Here is a new local timeout error

SqlException: Connection Timeout Expired. The timeout period elapsed during the post-login phase. The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting to create multiple active connections. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=5128; handshake=6505; [Login] initialization=499; authentication=965; [Post-Login] complete=4237;
Win32Exception: The wait operation timed out.

It also seems that increasing the timeout too much causes other application which use other databases on the same server to start timing out so I had to reduce it.

UPDATE: I finally found the paging example I used as a guide from MikesDotNetting https://www.mikesdotnetting.com/article/328/simple-paging-in-asp-net-core-razor-pages in which GetData() gets all the data he is using regardless of how much data there is. Now I'm being told that my GetPosts() is what is causing my app to crash due to there being too much data.

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
694 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,117 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 54,866 Reputation points
    2021-10-27T19:59:26.033+00:00

    its a simple prototype, that probably works up to 100 rows.

    this is a common design decision, what to do when the data display is more than trivial. web pages handle from around 50 - 100 rows of data. after that you need to add paging or filtering. google for dozens of paging demos.