BlazorOdataClient 0.0.1.9
dotnet add package BlazorOdataClient --version 0.0.1.9
NuGet\Install-Package BlazorOdataClient -Version 0.0.1.9
<PackageReference Include="BlazorOdataClient" Version="0.0.1.9" />
<PackageVersion Include="BlazorOdataClient" Version="0.0.1.9" />
<PackageReference Include="BlazorOdataClient" />
paket add BlazorOdataClient --version 0.0.1.9
#r "nuget: BlazorOdataClient, 0.0.1.9"
#:package BlazorOdataClient@0.0.1.9
#addin nuget:?package=BlazorOdataClient&version=0.0.1.9
#tool nuget:?package=BlazorOdataClient&version=0.0.1.9
Blazor Odata Client
This client library provides virtualization to an ODATA endpoint. This library extends the existing <Virtualize> component built into .net 6.
Package Manager
Install-Package BlazorOdataClient -Version 0.0.1.9
Client Program.cs
using BlazorOdataClient;
builder.Services.AddOdataClient(httpClientName: "ConsumerApp.ServerAPI");
Usage:
@using BlazorOdataClient
<OdataVirtualize @ref="view"
TItem="WeatherForecast"
EndPoint="WeatherForecast"
QueryString="$OrderBy=Date desc"
OverscanCount="4">
<tr>
<td>@context.Date.LocalDateTime.ToShortDateString()</td>
<td>@context.TemperatureC</td>
<td>@context.TemperatureF</td>
<td>@context.Summary</td>
</tr>
</OdataVirtualize>
Parameters:
| Parameter | |
|---|---|
| TItem | Specifies the type of item returned from the endpoint. |
| EndPoint | Specifies the odata endpoint to be appended to the bases addess from the HttpClient. This will be prefixed with "odata/" This can be changed via an optional parameter on AddOdataClient() |
| QueryString | Valid odata query. |
| OverscanCount | This is directly passed the blazor <Virtualize> component. Virtualization |
Endpoint used:
[Authorize]
[ApiController]
[Route(template: "api/[controller]")]
public class WeatherForecastController : ControllerBase
{
private readonly ApplicationDbContext dbContext;
public WeatherForecastController(ApplicationDbContext dbContext) => this.dbContext = dbContext;
[HttpGet]
[EnableQuery]
public IQueryable<WeatherForecast> Get() => dbContext.WeatherForecasts;
}
Note: the use of the IQueryable. This allows the query to be passed directly to the database engine. The benefit of this is often overlooked. Database engines are designed to sort, filter, query data. dbContext.WeatherForecasts is of type DbSet<WeatherForecast> which implements IQueryable<>
Server Program.cs
builder.Services.AddControllers().AddOData(options => options
.Select().Filter().OrderBy().SetMaxTop(maxTopValue: 100).SkipToken().Count()
.AddRouteComponents(routePrefix: "odata", OdataConfig.GetEdmModel()));
For the component to work the Edm approach is required. The following configures the WeatherForecast odata endpoint to the WeatherForecast API.
public static class OdataConfig
{
public static IEdmModel GetEdmModel()
{
var odataBuilder = new ODataConventionModelBuilder();
odataBuilder.EntitySet<WeatherForecast>(name: "WeatherForecast");
return odataBuilder.GetEdmModel();
}
}
I have tested this with 100,000 records and the performance was impressive.
Migrations and Seeding the demonstration app.
To rebuild the scripts I perform the following steps.
- Delete the database (close existing connections).
- Delete the Migrations folder under
\Data - Re-create the migration scripts From the package manager console: (making sure ConsumerApp.Server is the default project)
Add-Migration CreateInitialSchema -OutputDir Data/Migrations
- Update the database
Update-Database
This statement
builder.Services.AddOdataClient(httpClientName: "ConsumerApp.ServerAPI");
adds the following services for injection
public interface IOdataClientFactory
{
IOdataService<T> Create<T>(string endPoint);
IOdataService<T> Create<T>(string httpClientName, string endPoint);
}
public interface IOdataService<TItem>
{
ValueTask<OdataResponce<TItem>> GetOdataResponceAsync(string query);
ValueTask<int> GetItemCountAsync(string queryString = "");
ValueTask<ItemsProviderResult<TItem>> OdataPageAsync(ItemsProviderRequest request, string queryString);
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- Microsoft.AspNetCore.Components.Web (>= 6.0.0-rc.1.21452.15)
- Microsoft.AspNetCore.Components.WebAssembly.Authentication (>= 6.0.0-rc.1.21452.15)
- Microsoft.Extensions.Http (>= 6.0.0-rc.1.21451.13)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|
Note the change to an injectable service in the client for logging.