generated from Avanade/avanade-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- *Enhancement:* Enable JSON serialization of database parameter values; added `DatabaseParameterCollection.AddJsonParameter` method and associated `JsonParam`, `JsonParamWhen` and `JsonParamWith` extension methods. - *Enhancement:* Updated (simplified) `EventOutboxEnqueueBase` to pass events to the underlying stored procedures as JSON versus existing TVP removing database dependency on a UDT (user-defined type).
- Loading branch information
Showing
10 changed files
with
202 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
samples/My.Hr/My.Hr.Database/Migrations/20240930-132603-hr-spgetemployees.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CREATE OR ALTER PROCEDURE [Hr].[spGetEmployees] | ||
@Ids AS NVARCHAR(MAX) | ||
AS | ||
BEGIN | ||
SET NOCOUNT ON; | ||
|
||
-- Select the requested data. | ||
SELECT * FROM [Hr].[Employee] WHERE [EmployeeId] IN (SELECT VALUE FROM OPENJSON(@Ids)) | ||
END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using CoreEx.Database; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using My.Hr.Api; | ||
using My.Hr.Business.Data; | ||
using My.Hr.Business.Models; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using UnitTestEx.NUnit; | ||
|
||
namespace My.Hr.UnitTest | ||
{ | ||
[TestFixture] | ||
[Category("WithDB")] | ||
public class DatabaseTest | ||
{ | ||
[OneTimeSetUp] | ||
public static Task Init() => EmployeeControllerTest.Init(); | ||
|
||
[Test] | ||
public async Task DatabaseParameters_JsonParameter() | ||
{ | ||
using var test = ApiTester.Create<Startup>(); | ||
using var scope = test.Services.CreateScope(); | ||
|
||
var hrdb = scope.ServiceProvider.GetRequiredService<IDatabase>(); | ||
|
||
var ids = new List<Guid>(); | ||
await hrdb.SqlStatement("SELECT * FROM [Hr].[Employee]").SelectAsync(dr => | ||
{ | ||
ids.Add(dr.GetValue<Guid>("EmployeeId")); | ||
return true; | ||
}); | ||
|
||
var ids2 = new List<Guid>(); | ||
var c = hrdb.StoredProcedure("[Hr].[spGetEmployees]").JsonParamWith("", "ids", () => ids); | ||
|
||
await c.SelectAsync(dr => | ||
{ | ||
ids2.Add(dr.GetValue<Guid>("EmployeeId")); | ||
return true; | ||
}); | ||
|
||
Assert.That(ids, Is.EquivalentTo(ids2)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.