...

/

Getting Entities into a Component

Getting Entities into a Component

Learn about fetching data from the Northwind database, and implementing a component to display customer information.

Fetch data from the database

Now that we have seen the minimum implementation of a component, we can add some useful functionality to it. In this case, we will use the Northwind database context to fetch customers from the database:

Step 1: In Northwind.BlazorServer.csproj, add a reference to the Northwind database context project for either SQL Server or SQLite, as shown in the following markup:

Press + to interact
<ItemGroup>
<!-- change Sqlite to SqlServer if you prefer -->
<ProjectReference Include="..\Northwind.Common.DataContext.Sqlite\Northwind.Common.DataContext.Sqlite.csproj" />
</ItemGroup>

Step 2: Build the Northwind.BlazorServer project.

Step 3: In Program.cs, import the namespace for working with the Northwind database context extension method, as shown in the following code:

Press + to interact
using Packt.Shared; // AddNorthwindContext extension method

Step 4: In Program.cs, before the call ...