Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 42877bf

Browse files
miguelhassedvoituronvnbaaij
authoredNov 19, 2024··
[DataGrid] Add OData Adaptor package (#2938)
* OData client implementation for IAsyncQueryExecutor * Optimized count handling in ODataAsyncQueryExecutor * Removed empty unit tests project and added content to README file * Removed unused package references from Directory.Packages.props * Renamed project 'Microsoft.FluentUI.AspNetCore.Components.DataGrid.OData.Client' to 'Microsoft.FluentUI.AspNetCore.Components.DataGrid.ODataAdapter' --------- Co-authored-by: Denis Voituron <dvoituron@outlook.com> Co-authored-by: Vincent Baaij <vnbaaij@outlook.com>
1 parent a80f8f6 commit 42877bf

6 files changed

+150
-1
lines changed
 

‎Directory.Packages.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
<PackageVersion Include="bunit" Version="1.31.3" />
1818
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
1919
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
20-
<PackageVersion Include="xunit" Version="2.9.0" />
20+
<PackageVersion Include="xunit" Version="2.9.2" />
2121
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
2222
<PackageVersion Include="coverlet.msbuild" Version="6.0.0" />
2323
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
2424
<!-- Shared dependencies -->
2525
<PackageVersion Include="Markdig.Signed" Version="0.34.0" />
2626
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
2727
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
28+
<PackageVersion Include="Microsoft.OData.Client" Version="8.2.1" />
2829
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.20" />
2930
<PackageVersion Include="Microsoft.VisualStudioEng.MicroBuild.Core" Version="1.0.0" />
3031
</ItemGroup>

‎Microsoft.FluentUI.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FluentUI.Demo.AssetExplorer
4343
EndProject
4444
Project("{54A90642-561A-4BB1-A94E-469ADEE60C69}") = "Microsoft.FluentUI.AspNetCore.Components.Assets", "src\Core.Assets\Microsoft.FluentUI.AspNetCore.Components.Assets.esproj", "{292081C2-5076-467C-AEFF-12DC0617531A}"
4545
EndProject
46+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.FluentUI.AspNetCore.Components.DataGrid.ODataAdapter", "src\Extensions\DataGrid.ODataAdapter\Microsoft.FluentUI.AspNetCore.Components.DataGrid.ODataAdapter.csproj", "{AFFDA282-83AB-44FA-B400-C935BBFE3308}"
47+
EndProject
4648
Global
4749
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4850
Debug|Any CPU = Debug|Any CPU
@@ -95,6 +97,10 @@ Global
9597
{292081C2-5076-467C-AEFF-12DC0617531A}.Release|Any CPU.ActiveCfg = Release|Any CPU
9698
{292081C2-5076-467C-AEFF-12DC0617531A}.Release|Any CPU.Build.0 = Release|Any CPU
9799
{292081C2-5076-467C-AEFF-12DC0617531A}.Release|Any CPU.Deploy.0 = Release|Any CPU
100+
{AFFDA282-83AB-44FA-B400-C935BBFE3308}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
101+
{AFFDA282-83AB-44FA-B400-C935BBFE3308}.Debug|Any CPU.Build.0 = Debug|Any CPU
102+
{AFFDA282-83AB-44FA-B400-C935BBFE3308}.Release|Any CPU.ActiveCfg = Release|Any CPU
103+
{AFFDA282-83AB-44FA-B400-C935BBFE3308}.Release|Any CPU.Build.0 = Release|Any CPU
98104
EndGlobalSection
99105
GlobalSection(SolutionProperties) = preSolution
100106
HideSolutionNode = FALSE
@@ -117,6 +123,7 @@ Global
117123
{17F26C55-E329-4117-B64D-0393E912FFFE} = {9468ADD1-3660-410D-8231-6F89384D135D}
118124
{E4E62EAA-38FC-48FE-B63E-EB4ABAD660D2} = {17F26C55-E329-4117-B64D-0393E912FFFE}
119125
{292081C2-5076-467C-AEFF-12DC0617531A} = {DF88C07D-46D7-4DEC-ACE4-409217634E57}
126+
{AFFDA282-83AB-44FA-B400-C935BBFE3308} = {1199ECBA-EE19-44CD-A471-85AB2F44489C}
120127
EndGlobalSection
121128
GlobalSection(ExtensibilityGlobals) = postSolution
122129
SolutionGuid = {420693A7-C2FD-498C-8E78-4B65CC25389A}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
5+
<PackageId>Microsoft.FluentUI.AspNetCore.Components.DataGrid.ODataAdapter</PackageId>
6+
<Authors>Microsoft</Authors>
7+
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
8+
<NeutralLanguage>en</NeutralLanguage>
9+
<Owners>Microsoft Corporation</Owners>
10+
<PackageProjectUrl>https://github.com/microsoft/fluentui-blazor</PackageProjectUrl>
11+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
12+
<Summary>An adapter for using the Fluent UI Blazor DataGrid with OData Client.</Summary>
13+
<PackageTags>Fluent UI, Blazor, DataGrid, .NET8</PackageTags>
14+
<Title>Microsoft Fluent UI DataGrid adapter for Entity Framework</Title>
15+
<Description>An adapter for using the Fluent UI Blazor DataGrid with OData Client.</Description>
16+
<SignAssembly>false</SignAssembly>
17+
<Nullable>enable</Nullable>
18+
<ImplicitUsings>enable</ImplicitUsings>
19+
<DebugType>embedded</DebugType>
20+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
21+
22+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
23+
<RepositoryUrl>https://github.com/microsoft/fluentui-blazor</RepositoryUrl>
24+
<RepositoryType>git</RepositoryType>
25+
<PackageReadmeFile>README.md</PackageReadmeFile>
26+
<LangVersion>latest</LangVersion>
27+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
28+
<IsPackable>true</IsPackable>
29+
<PackageIcon>icon.png</PackageIcon>
30+
</PropertyGroup>
31+
32+
<PropertyGroup Condition="'$(Configuration)'=='Release'">
33+
<IsShipping>true</IsShipping>
34+
<Optimize>True</Optimize>
35+
<NoWarn>1701;1702;8669;1591</NoWarn>
36+
<DebuggerSupport>false</DebuggerSupport>
37+
<TrimmerRemoveSymbols>true</TrimmerRemoveSymbols>
38+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
39+
<PackageOutputPath>$(SolutionDir)artifacts</PackageOutputPath>
40+
</PropertyGroup>
41+
42+
<ItemGroup>
43+
<PackageReference Include="Microsoft.OData.Client" />
44+
<PackageReference Include="Microsoft.VisualStudioEng.MicroBuild.Core">
45+
<PrivateAssets>all</PrivateAssets>
46+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
47+
</PackageReference>
48+
</ItemGroup>
49+
50+
<ItemGroup>
51+
<ProjectReference Include="..\..\Core\Microsoft.FluentUI.AspNetCore.Components.csproj" />
52+
</ItemGroup>
53+
54+
<ItemGroup>
55+
<None Include="README.md" Pack="true" PackagePath="\" />
56+
<None Include="..\..\..\icon.png" Pack="true" PackagePath="\" />
57+
</ItemGroup>
58+
59+
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true' Or '$(TF_BUILD)' == 'true'">
60+
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
61+
</PropertyGroup>
62+
63+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.FluentUI.AspNetCore.Components.DataGrid.ODataAdapter;
2+
using Microsoft.FluentUI.AspNetCore.Components.DataGrid.Infrastructure;
3+
4+
namespace Microsoft.Extensions.DependencyInjection;
5+
6+
/// <summary>
7+
/// Provides extension methods to configure <see cref="IAsyncQueryExecutor"/> on a <see cref="IServiceCollection"/>.
8+
/// </summary>
9+
public static class ODataAdapterServiceCollectionExtensions
10+
{
11+
/// <summary>
12+
/// Registers an OData aware implementation of <see cref="IAsyncQueryExecutor"/>.
13+
/// </summary>
14+
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
15+
public static void AddDataGridODataAdapter(this IServiceCollection services)
16+
{
17+
services.AddScoped<IAsyncQueryExecutor, ODataAsyncQueryExecutor>();
18+
}
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.OData.Client;
2+
using Microsoft.FluentUI.AspNetCore.Components.DataGrid.Infrastructure;
3+
4+
namespace Microsoft.FluentUI.AspNetCore.Components.DataGrid.ODataAdapter;
5+
6+
internal class ODataAsyncQueryExecutor : IAsyncQueryExecutor
7+
{
8+
public bool IsSupported<T>(IQueryable<T> queryable) => queryable.Provider is DataServiceQueryProvider;
9+
10+
public async Task<int> CountAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken)
11+
=> (int)(await ExecuteAsync(((DataServiceQuery<T>)queryable.Take(0)).IncludeCount(), cancellationToken)).Count;
12+
13+
public async Task<T[]> ToArrayAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken)
14+
=> [.. await ExecuteAsync(queryable, cancellationToken)];
15+
16+
private static async Task<QueryOperationResponse<T>> ExecuteAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken)
17+
{
18+
return (QueryOperationResponse<T>)await ((DataServiceQuery<T>)queryable).ExecuteAsync(cancellationToken);
19+
}
20+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## About
2+
Use this package if the data you want to display in the `FluentDataGrid` (component in the `Microsoft.FluentUI.AspNetCore.Components library`) comes from [Microsoft.OData.Client](https://www.nuget.org/packages/Microsoft.OData.Client).
3+
4+
Microsoft OData Client library's DataServiceContext gives you a DataServiceQuery property for each resource in your OData service endpoint. Simply supply this as the grid's RowsData parameter:
5+
```
6+
@inject DataServiceContext MyServiceContext
7+
8+
<FluentDataGrid RowsData="@MyServiceContext.People">
9+
...
10+
</FluentDataGrid>
11+
```
12+
13+
You may also use any DataServiceQuery-supported LINQ operator to filter the data before passing it:
14+
```
15+
@inject DataServiceContext MyServiceContext
16+
17+
<FluentDataGrid RowsData="@MyServiceContext.Documents.Where(d => d.CategoryId == currentCategoryId)">
18+
...
19+
</FluentDataGrid>
20+
```
21+
22+
The `FluentDataGrid` recognizes DataServiceQuery-supplied `IQueryable` instances and knows how to resolve queries asynchronously for efficiency.
23+
24+
## Installation
25+
Install the package by running the command:
26+
```
27+
dotnet add package Microsoft.FluentUI.AspNetCore.Components.DataGrid.ODataAdapter
28+
```
29+
30+
## Usage
31+
In your Program.cs file you need to add the following:
32+
```
33+
builder.Services.AddDataGridODataAdapter();
34+
```
35+
36+
## Support
37+
The Microsoft Fluent UI Blazor library is an open source project and is **not** an official part of ASP.NET Core, which means it’s **not** officially
38+
supported and isn’t committed to ship updates as part of any official .NET updates. It is built and maintained by Microsoft employees (**and** other contributors)
39+
and offers support, like most other open source projects, on a best effort base through the GitHub repository **only**.

0 commit comments

Comments
 (0)
Please sign in to comment.