I'm trying to learn Radzen & Blazor, so instead of using a stored procedure or view to query the data the way I want it, I wanted to try putting together a custom method. Following the documented procedures, I wasn't even coming close. So, I though I'd start a new project and follow the tutorial - Blazor Invoke method - Perform custom database query.
As soon as I pasted the custom code into visual studio, I could tell that there was something very wrong. Here's what I have for orders.razor.cs :
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Radzen;
using Radzen.Blazor;
namespace Northwind.Pages
{
public partial class OrdersComponent
{
[Inject]
NorthwindContext NorthwindContext { get; set; }
public int OrdersByCountry(string country)
{
var orders = NorthwindContext.Orders.Where(o => o.ShipCountry == country);
return orders.Count();
}
}
}
Visual Studio is showing the same errors as Radzen. Here's what Radzen produces when I run the project:
radzen: Generating code ...
radzen: Code generation done in 678ms.
dotnet: watch :
dotnet: Started
dotnet: Pages\Orders.razor.cs(15,9): error CS0246: The type or namespace name 'NorthwindContext' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\DevVM\Documents\RadzenProjects\NorthWind\server\Northwind.csproj]
dotnet: Pages\Orders.razor.cs(14,10): error CS0246: The type or namespace name 'InjectAttribute' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\DevVM\Documents\RadzenProjects\NorthWind\server\Northwind.csproj]
Pages\Orders.razor.cs(14,10): error CS0246: The type or namespace name 'Inject' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\DevVM\Documents\RadzenProjects\NorthWind\server\Northwind.csproj]
dotnet:
dotnet: The build failed. Fix the build errors and run again.
dotnet: watch : Exited with error code 1
dotnet: watch : Waiting for a file to change before restarting dotnet...
I believe I was able to fix the Inject issues by putting in the same directives that are used in the designer files. But, I've searched all files in the project, and there are no Types, Namespaces, or anything with the word "NorthwindContext" anywhere. Shouldn't there be a reference to it in startup.cs?
I've read all of the Blazor documentation, and every Blazor community post regarding custom methods carefully. But, I'm still learning this platform and am likely doing something ridiculously stupid.
Thanks for any help you can provide,
Stephen