Fixing Some Warnings
In this lesson, we're going to fix some warnings
Get the project source code below, and follow along with the lesson material.
Download Project Source CodeTo set up the project on your local machine, please follow the directions provided in the README.md
file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.
This lesson preview is part of the The newline Guide to Fullstack ASP.NET Core and React course and can be unlocked immediately with a single-time purchase. Already have access to this course? Log in here.
Get unlimited access to The newline Guide to Fullstack ASP.NET Core and React with a single-time purchase.

[00:00 - 00:11] We have done pretty well with the API so far, but you might notice some warnings in the way. If we add more than two navigation properties in the include statement, let me show it to you.
[00:12 - 00:27] Let's open courses with category specification. And here, let's add another include statement using the category.
[00:28 - 00:39] And if we go to postman and run the get cost request with an ID, now let's send it. Now this works fine.
[00:40 - 01:12] And we see the category as well. But if we open our terminal and we see a warning here, which says compiling a query, which loads related collections for more than one collection navigation either via include or through projection, but no query splitting behavior has been configured by default entity framework will use query splitting behavior dot single query, which can potentially result in slow query performance.
[01:13 - 01:32] Now what does that mean? This simply means that the entity framework core is using a single query by default, which means that when we have lots of navigation properties, like in this one, we have three navigation properties, we have too many inner joins in the SQL query, which is causing this slow performance.
[01:33 - 01:42] We can either ignore this warning by writing a piece of code, or we can change the behavior in which the query is being made. I would choose the later for that.
[01:43 - 02:01] What we'll do is let's reduce the size and go to our startup class. Inside the configure services method, inside services dot add DB context, we will configure our query splitting behavior.
[02:02 - 02:21] Let's take that off and use a comma here instead. And here we will write x, which goes to x dot use query splitting behavior.
[02:22 - 02:38] And inside we will write query splitting behavior dot split query. Let me get rid of that bracket here and use it here and put a semicolon.
[02:39 - 02:58] By default, it is using query splitting behavior dot single query, but we are changing it to a split query. What it will do is rather than making a single query with all the inner joins for adding navigation properties, it will split the query into one or more paths so that it doesn't impact the performance.
[02:59 - 03:06] Let's do one thing. Let's run that request again.
[03:07 - 03:20] Go back to the terminal. And here we see another warning.
[03:21 - 03:40] It says the query uses a rule limiting operator skip take without an order by this may lead to unpredictable results. It means since it's making more than one request and it doesn't have order by in the request, it doesn't guarantee us any order.
[03:41 - 03:50] Again, we can either ignore it or write an order by. So although we have made a sort method, which is using the order by.
[03:51 - 04:02] So what we can do is we can simply use it here. What we'll do is use sort method and inside we will sort it by the ID.
[04:03 - 04:20] Since we are here and we are configuring this, we can simply include the learn ings and requirements to our get courses method. We might use it somewhere for a better customer experience.
[04:21 - 04:39] But we can also use the sort method inside categories with courses because otherwise it'll give us the same warning because it's not using any order by. Now what we'll do is make the request again.
[04:40 - 04:48] Check the terminal. we don't have any other warnings anymore. Which is great.