Skip to content

Commit 5267efc

Browse files
authored
v5.15.0 (#254)
* v5.15.0 Enhancement: Added Operation.Query boolean to enable support for OData-like query syntax. This leverages the underlying CoreEx.Data.Querying capabilities to enable. The Operation.Behavior has also been extened to support a 'Q'uery as a shorthand to enable a query operation. Enhancement: Updated the DatabaseName, EntityFrameworkName, CosmosName, ODataName and HttpAgentName to support both Type (existing) and optional Name (new). This uses the Type^Name syntax supported for other properties with similar purpose. The properties have also had the Name suffix renamed to Type as this more accurately reflects the property intent (existing names will continue to work with a corresponding warning during code-generation). * Add missing Cosmos template CI test * Fix cosmos template. * Tweaks and fixes.
1 parent 2edb83a commit 5267efc

File tree

105 files changed

+1149
-286
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1149
-286
lines changed

.github/workflows/CI.yml

+14
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
Bar_ConnectionStrings__Database: Data Source=localhost,1433;Initial Catalog=Foo.Bar;User id=sa;Password=sAPWD23.^0;TrustServerCertificate=true
2626
Bam_ConnectionStrings__Database: Server=localhost;Port=3306;Database=Foo.Bam;Uid=ciuser;Pwd=ciStrong#!Password;AllowUserVariables=true;UseAffectedRows=false;
2727
Bap_ConnectionStrings__Database: Server=localhost;Port=5432;Database=Foo.Bap;User Id=postgres;Pwd=ciStrong#!Password;
28+
Bac_CosmosConnectionString: ${{ secrets.COSMOS_CONNECTION_STRING }}
2829
Cdr_CosmosConnectionString: ${{ secrets.COSMOS_CONNECTION_STRING }}
2930

3031
services:
@@ -329,4 +330,17 @@ jobs:
329330

330331
- name: Template/SqlServer/EfWs services test
331332
working-directory: ./Foo.EfWs.Bar/Foo.EfWs.Bar.Services.Test
333+
run: dotnet test
334+
335+
# Template - CosmosDB
336+
337+
- name: Template/Cosmos create
338+
run: dotnet new beef --company Foo.Co --appname Bac --datasource Cosmos --output Foo.Co.Bac
339+
340+
- name: Template/Cosmos code-gen
341+
working-directory: ./Foo.Co.Bac/Foo.Co.Bac.CodeGen
342+
run: dotnet run all
343+
344+
- name: Template/Cosmos test
345+
working-directory: ./Foo.Co.Bac
332346
run: dotnet test

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Represents the **NuGet** versions.
44

5+
## v5.15.0
6+
- *Enhancement:* Added `Operation.Query` boolean to enable support for OData-like query syntax. This leverages the underlying `CoreEx.Data.Querying` (`v3.25.1+`) capabilities to enable. The `Operation.Behavior` has also been extended to support a '`Q`'uery as a shorthand to enable a query-based operation. _Note:_ this is an **awesome** new capability.
7+
- *Enhancement:* Updated the `DatabaseName`, `EntityFrameworkName`, `CosmosName`, `ODataName` and `HttpAgentName` to support both `Type` (existing) and optional `Name` (new). This uses the `Type^Name` syntax supported for other properties with similar purpose. The properties have also had the `Name` suffix renamed to `Type` as this more accurately reflects the property intent (existing names will continue to work with a corresponding warning during code-generation).
8+
59
## v5.14.2
610
- *Fixed:* Fixed the data model code-generation to output the `PartitionKey` where specified.
711
- *Fixed:* Fixed the code-generated `PartitionKey` to be a nullable string.

Common.targets

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>5.14.2</Version>
3+
<Version>5.15.0</Version>
44
<LangVersion>preview</LangVersion>
55
<Authors>Avanade</Authors>
66
<Company>Avanade</Company>

docs/Entity-CodeGeneration-Config.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Provides the _Database Data-layer_ configuration.
135135

136136
Property | Description
137137
-|-
138-
**`databaseName`** | The .NET database interface name (used where `Operation.AutoImplement` is `Database`).<br/>&dagger; Defaults to `IDatabase`. This can be overridden within the `Entity`(s).
138+
**`databaseType`** | The .NET database type and optional name (used where `Operation.AutoImplement` is `Database`).<br/>&dagger; Defaults to `IDatabase`. Should be formatted as `Type` + `^` + `Name`; e.g. `IDatabase^Db`. Where the `Name` portion is not specified it will be inferred. This can be overridden within the `Entity`(s).
139139
**`databaseSchema`** | The default database schema name.<br/>&dagger; Defaults to `dbo`.
140140
**`databaseProvider`** | The default database schema name. Valid options are: `SqlServer`, `MySQL`, `Postgres`.<br/>&dagger; Defaults to `SqlServer`. Enables specific database provider functionality/formatting/etc. where applicable.
141141
`databaseMapperEx` | Indicates that a `DatabaseMapperEx` will be used; versus, `DatabaseMapper` (which uses Reflection internally).<br/>&dagger; Defaults to `true`. The `DatabaseMapperEx` essentially replaces the `DatabaseMapper` as it is more performant (extended/explicit); this option can be used where leagcy/existing behavior is required.
@@ -147,7 +147,7 @@ Provides the _Entity Framewotrk (EF) Data-layer_ configuration.
147147

148148
Property | Description
149149
-|-
150-
`entityFrameworkName` | The .NET Entity Framework interface name used where `Operation.AutoImplement` is `EntityFramework`.<br/>&dagger; Defaults to `IEfDb`. This can be overridden within the `Entity`(s).
150+
`entityFrameworkType` | The .NET Entity Framework type and optional name (used where `Operation.AutoImplement` is `EntityFramework`).<br/>&dagger; Defaults to `IEfDb`. Should be formatted as `Type` + `^` + `Name`; e.g. `IEfDb^Ef`. Where the `Name` portion is not specified it will be inferred. This can be overridden within the `Entity`(s).
151151

152152
<br/>
153153

@@ -156,7 +156,7 @@ Provides the _CosmosDB Data-layer_ configuration.
156156

157157
Property | Description
158158
-|-
159-
**`cosmosName`** | The .NET Entity Framework interface name used where `Operation.AutoImplement` is `Cosmos`.<br/>&dagger; Defaults to `ICosmosDb`. This can be overridden within the `Entity`(s).
159+
**`cosmosType`** | The .NET Cosmos DB type and name (used where `Operation.AutoImplement` is `Cosmos`).<br/>&dagger; Defaults to `ICosmosDb`. Should be formatted as `Type` + `^` + `Name`; e.g. `ICosmosDb^Cosmos`. Where the `Name` portion is not specified it will be inferred. This can be overridden within the `Entity`(s).
160160

161161
<br/>
162162

@@ -165,7 +165,7 @@ Provides the _OData Data-layer_ configuration.
165165

166166
Property | Description
167167
-|-
168-
**`odataName`** | The .NET OData interface name used where `Operation.AutoImplement` is `OData`.<br/>&dagger; Defaults to `IOData`. This can be overridden within the `Entity`(s).
168+
**`odataType`** | The .NET OData interface name used where `Operation.AutoImplement` is `OData`.<br/>&dagger; Defaults to `IOData`. Should be formatted as `Type` + `^` + `Name`; e.g. `IOData^OData`. Where the `Name` portion is not specified it will be inferred. This can be overridden within the `Entity`(s).
169169

170170
<br/>
171171

@@ -174,7 +174,7 @@ Provides the _HTTP Agent Data-layer_ configuration.
174174

175175
Property | Description
176176
-|-
177-
**`httpAgentName`** | The default .NET HTTP Agent interface name used where `Operation.AutoImplement` is `HttpAgent`.<br/>&dagger; Defaults to `IHttpAgent`. This can be overridden within the `Entity`(s).
177+
**`httpAgentType`** | The default .NET HTTP Agent interface name used where `Operation.AutoImplement` is `HttpAgent`.<br/>&dagger; Defaults to `IHttpAgent`. Should be formatted as `Type` + `^` + `Name`; e.g. `IHttpAgent^HttpAgent`. Where the `Name` portion is not specified it will be inferred. This can be overridden within the `Entity`(s).
178178

179179
<br/>
180180

docs/Entity-Entity-Config.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,11 @@ Provides the _Operation_ configuration. These primarily provide a shorthand to c
121121

122122
Property | Description
123123
-|-
124-
`behavior` | Defines the key CRUD-style behavior (operation types), being 'C'reate, 'G'et (or 'R'ead), 'U'pdate, 'P'atch and 'D'elete). Additionally, GetByArgs ('B') and GetAll ('A') operations that will be automatically generated where not otherwise explicitly specified.<br/>&dagger; Value may only specifiy one or more of the `CGRUDBA` characters (in any order) to define the automatically generated behavior (operations); for example: `CRUPD` or `CRUP` or `rba` (case insensitive). This is shorthand for setting one or more of the following properties: `Get`, `GetByArgs`, `GetAll`, 'Create', `Update`, `Patch` and `Delete`. Where one of these properties is set to either `true` or `false` this will take precedence over the value set for `Behavior`.
124+
`behavior` | Defines the key CRUD-style behavior (operation types), being 'C'reate, 'G'et (or 'R'ead), 'U'pdate, 'P'atch, 'D'elete and `Q`uery). Additionally, `GetByArgs` ('B'), `GetAll` ('A') and `GetByQuery` ('Q') operations configuration will be automatically inferred where not otherwise explicitly specified.<br/>&dagger; Value may only specifiy one or more of the `CGRUDBAQ` characters (in any order) to define the automatically generated behavior (operations); for example: `CRUPD` or `CRUP` or `rba` (case insensitive). This is shorthand for setting one or more of the following properties: `Get`, `GetByArgs`, `GetAll`, 'Create', `Update`, `Patch` and `Delete`. Where one of these properties is set to either `true` or `false` this will take precedence over the value set for `Behavior`.
125125
`get` | Indicates that a `Get` operation will be automatically generated where not otherwise explicitly specified.
126126
`getByArgs` | Indicates that a `GetByArgs` operation will be automatically generated where not otherwise explicitly specified.
127127
`getAll` | Indicates that a `GetAll` operation will be automatically generated where not otherwise explicitly specified.
128+
`getByQuery` | Indicates that a `GetByQuery` operation will be automatically generated where not otherwise explicitly specified.
128129
`create` | Indicates that a `Create` operation will be automatically generated where not otherwise explicitly specified.
129130
`update` | Indicates that a `Update` operation will be automatically generated where not otherwise explicitly specified.
130131
`patch` | Indicates that a `Patch` operation will be automatically generated where not otherwise explicitly specified.
@@ -217,7 +218,7 @@ Provides the specific _Database (ADO.NET)_ configuration where `AutoImplement` i
217218

218219
Property | Description
219220
-|-
220-
**`databaseName`** | The .NET database interface name (used where `AutoImplement` is `Database`).<br/>&dagger; Defaults to the `CodeGeneration.DatabaseName` configuration property (its default value is `IDatabase`).
221+
**`databaseType`** | The .NET database type and optional name (used where `AutoImplement` is `Database`).<br/>&dagger; Defaults to the `CodeGeneration.DatabaseName` configuration property (its default value is `IDatabase`). Should be formatted as `Type` + `^` + `Name`.
221222
**`databaseSchema`** | The database schema name (used where `AutoImplement` is `Database`).<br/>&dagger; Defaults to `dbo`.
222223
`databaseMapperInheritsFrom` | The name of the `Mapper` that the generated Database `Mapper` inherits from.
223224
`databaseCustomMapper` | Indicates that a custom Database `Mapper` will be used; i.e. not generated.<br/>&dagger; Otherwise, by default, a `Mapper` will be generated.
@@ -230,7 +231,7 @@ Provides the specific _Entity Framework (EF)_ configuration where `AutoImplement
230231

231232
Property | Description
232233
-|-
233-
**`entityFrameworkName`** | The .NET Entity Framework interface name used where `AutoImplement` is `EntityFramework`.<br/>&dagger; Defaults to `CodeGeneration.EntityFrameworkName`.
234+
**`entityFrameworkType`** | The .NET Entity Framework type and optyional name used where `AutoImplement` is `EntityFramework`.<br/>&dagger; Defaults to `CodeGeneration.EntityFrameworkName`. Should be formatted as `Type` + `^` + `Name`.
234235
**`entityFrameworkModel`** | The corresponding Entity Framework model name (required where `AutoImplement` is `EntityFramework`).
235236
`entityFrameworkCustomMapper` | Indicates that a custom Entity Framework `Mapper` will be used; i.e. not generated.<br/>&dagger; Otherwise, by default, a `Mapper` will be generated.
236237
`entityFrameworkMapperBase` | The EntityFramework data-layer name that should be used for base mappings.
@@ -242,7 +243,7 @@ Provides the specific _Cosmos_ configuration where `AutoImplement` is `Cosmos`.
242243

243244
Property | Description
244245
-|-
245-
**`cosmosName`** | The .NET Cosmos interface name used where `AutoImplement` is `Cosmos`.<br/>&dagger; Defaults to the `CodeGeneration.CosmosName` configuration property (its default value is `ICosmosDb`).
246+
**`cosmosType`** | The .NET Cosmos DB type and optional name used where `AutoImplement` is `Cosmos`.<br/>&dagger; Defaults to the `CodeGeneration.CosmosName` configuration property (its default value is `ICosmosDb`). Should be formatted as `Type` + `^` + `Name`.
246247
**`cosmosModel`** | The corresponding Cosmos model name (required where `AutoImplement` is `Cosmos`).
247248
**`cosmosContainerId`** | The Cosmos `ContainerId` required where `AutoImplement` is `Cosmos`.
248249
`cosmosPartitionKey` | The C# code to be used for setting the optional Cosmos `PartitionKey` where `AutoImplement` is `Cosmos`.<br/>&dagger; The value `PartitionKey.None` can be specified. Literals will need to be quoted.
@@ -258,7 +259,7 @@ Provides the specific _OData_ configuration where `AutoImplement` is `OData`.
258259

259260
Property | Description
260261
-|-
261-
**`odataName`** | The .NET OData interface name used where `AutoImplement` is `OData`.<br/>&dagger; Defaults to the `CodeGeneration.ODataName` configuration property (its default value is `IOData`).
262+
**`odataType`** | The .NET OData type and optional name used where `AutoImplement` is `OData`.<br/>&dagger; Defaults to the `CodeGeneration.ODataName` configuration property (its default value is `IOData`). Should be formatted as `Type` + `^` + `Name`.
262263
**`odataModel`** | The corresponding OData model name (required where `AutoImplement` is `OData`).
263264
**`odataCollectionName`** | The name of the underlying OData collection where `AutoImplement` is `OData`.<br/>&dagger; The underlying `Simple.OData.Client` will attempt to infer.
264265
`odataCustomMapper` | Indicates that a custom OData `Mapper` will be used; i.e. not generated.<br/>&dagger; Otherwise, by default, a `Mapper` will be generated.
@@ -271,7 +272,7 @@ Provides the specific _HTTP Agent_ configuration where `AutoImplement` is `HttpA
271272

272273
Property | Description
273274
-|-
274-
**`httpAgentName`** | The .NET HTTP Agent interface name used where `Operation.AutoImplement` is `HttpAgent`.<br/>&dagger; Defaults to `CodeGeneration.HttpAgentName` configuration property (its default value is `IHttpAgent`).
275+
**`httpAgentType`** | The .NET HTTP Agent type and optional name used where `Operation.AutoImplement` is `HttpAgent`.<br/>&dagger; Defaults to `CodeGeneration.HttpAgentName` configuration property (its default value is `IHttpAgent`). Should be formatted as `Type` + `^` + `Name`.
275276
`httpAgentRoutePrefix` | The base HTTP Agent API route where `Operation.AutoImplement` is `HttpAgent`.<br/>&dagger; This is the base (prefix) `URI` for the HTTP Agent endpoint and can be further extended when defining the underlying `Operation`(s).
276277
**`httpAgentModel`** | The corresponding HTTP Agent model name (required where `AutoImplement` is `HttpAgent`).<br/>&dagger; This can be overridden within the `Operation`(s).
277278
`httpAgentReturnModel` | The corresponding HTTP Agent model name (required where `AutoImplement` is `HttpAgent`).<br/>&dagger; This can be overridden within the `Operation`(s).

docs/Entity-Operation-Config.md

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Property | Description
6969
`text` | The text for use in comments.<br/>&dagger; The `Text` will be defaulted for all the `Operation.Type` options with the exception of `Custom`. To create a `<see cref="XXX"/>` within use moustache shorthand (e.g. {{Xxx}}). To have the text used as-is prefix with a `+` plus-sign character.
7070
**`primaryKey`** | Indicates whether the properties marked as a primary key (`Property.PrimaryKey`) are to be used as the parameters.<br/>&dagger; This simplifies the specification of these properties as parameters versus having to declare each specifically. Each of the parameters will also be set to be mandatory.
7171
**`paging`** | Indicates whether a `PagingArgs` argument is to be added to the operation to enable (standardized) paging related logic.
72+
**`query`** | Indicates whether a `QueryArgs` argument is to be added to the operation to enable OData-like $filter and $orderby related logic.
7273
`valueType` | The .NET value parameter `Type` for the operation.<br/>&dagger; Defaults to the parent `Entity.Name` where the `Operation.Type` options are `Create` or `Update`.
7374
`returnType` | The .NET return `Type` for the operation.<br/>&dagger; Defaults to the parent `Entity.Name` where the `Operation.Type` options are `Get`, `GetColl`, `Create` or `Update`; otherwise, defaults to `void`.
7475
`returnTypeNullable` | Indicates whether the `ReturnType` is nullable for the operation.<br/>&dagger; Will be inferred where the `ReturnType` is denoted as nullable; i.e. suffixed by a `?`. Additionally a `Type` of `Get` will default to `true` where not specified.

samples/Cdr.Banking/Cdr.Banking.Api/Cdr.Banking.Api.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<ImplicitUsings>true</ImplicitUsings>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageReference Include="CoreEx.AspNetCore" Version="3.24.1" />
9-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.7.0" />
8+
<PackageReference Include="CoreEx.AspNetCore" Version="3.25.1" />
9+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.7.3" />
1010
</ItemGroup>
1111
<ItemGroup>
1212
<ProjectReference Include="..\Cdr.Banking.Business\Cdr.Banking.Business.csproj" />

samples/Cdr.Banking/Cdr.Banking.Api/Controllers/Generated/AccountController.cs

+13
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ public Task<IActionResult> GetAccounts([FromQuery(Name="product-category")] stri
4343
return _webApi.GetWithResultAsync<AccountCollectionResult>(Request, p => _manager.GetAccountsAsync(args, p.RequestOptions.Paging), alternateStatusCode: HttpStatusCode.NoContent);
4444
}
4545

46+
/// <summary>
47+
/// Get all accounts.
48+
/// </summary>
49+
/// <returns>The <c>Account</c> array</returns>
50+
[Tags("Banking", "Accounts")]
51+
[HttpGet("api/v1/banking/accounts/query", Name="Account_GetAccountsQuery")]
52+
[Paging]
53+
[Query]
54+
[ProducesResponseType(typeof(Common.Entities.AccountCollection), (int)HttpStatusCode.OK)]
55+
[ProducesResponseType((int)HttpStatusCode.NoContent)]
56+
public Task<IActionResult> GetAccountsQuery()
57+
=> _webApi.GetWithResultAsync<AccountCollectionResult>(Request, p => _manager.GetAccountsQueryAsync(p.RequestOptions.Query, p.RequestOptions.Paging), alternateStatusCode: HttpStatusCode.NoContent);
58+
4659
/// <summary>
4760
/// Get <c>AccountDetail</c>.
4861
/// </summary>

samples/Cdr.Banking/Cdr.Banking.Api/Startup.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ public void ConfigureServices(IServiceCollection services)
3030
.AddValidators<AccountManager>();
3131

3232
// Add the cosmos database.
33-
services.AddSingleton<ICosmos>(sp =>
33+
services.AddSingleton(sp =>
3434
{
3535
var settings = sp.GetRequiredService<BankingSettings>();
3636
var cco = new AzCosmos.CosmosClientOptions { SerializerOptions = new AzCosmos.CosmosSerializationOptions { PropertyNamingPolicy = AzCosmos.CosmosPropertyNamingPolicy.CamelCase, IgnoreNullValues = true } };
37-
return new CosmosDb(new AzCosmos.CosmosClient(settings.CosmosConnectionString, cco).GetDatabase(settings.CosmosDatabaseId), sp.GetRequiredService<CoreEx.Mapping.IMapper>());
37+
return new AzCosmos.CosmosClient(settings.CosmosConnectionString, cco);
38+
});
39+
40+
services.AddCosmosDb<ICosmos>(sp =>
41+
{
42+
var settings = sp.GetRequiredService<BankingSettings>();
43+
return new CosmosDb(sp.GetRequiredService<AzCosmos.CosmosClient>().GetDatabase(settings.CosmosDatabaseId), sp.GetRequiredService<CoreEx.Mapping.IMapper>());
3844
});
3945

4046
// Add the generated reference data services.
@@ -60,6 +66,7 @@ public void ConfigureServices(IServiceCollection services)
6066
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Cdr.Banking API", Version = "v1" });
6167
options.OperationFilter<AcceptsBodyOperationFilter>(); // Needed to support AcceptsBodyAttribute where body parameter not explicitly defined.
6268
options.OperationFilter<PagingOperationFilter>(); // Needed to support PagingAttribute where PagingArgs parameter not explicitly defined.
69+
options.OperationFilter<QueryOperationFilter>(); // Needed to support QueryAttribute where QueryArgs parameter not explicitly defined.
6370
});
6471
}
6572

samples/Cdr.Banking/Cdr.Banking.Business/Cdr.Banking.Business.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
<Folder Include="DataSvc\" />
1313
</ItemGroup>
1414
<ItemGroup>
15-
<PackageReference Include="CoreEx.AspNetCore" Version="3.24.1" />
16-
<PackageReference Include="CoreEx.Cosmos" Version="3.24.1" />
17-
<PackageReference Include="CoreEx.Validation" Version="3.24.1" />
15+
<PackageReference Include="CoreEx.AspNetCore" Version="3.25.1" />
16+
<PackageReference Include="CoreEx.Cosmos" Version="3.25.1" />
17+
<PackageReference Include="CoreEx.Validation" Version="3.25.1" />
1818
</ItemGroup>
1919
</Project>

0 commit comments

Comments
 (0)