From 736bb4c8d05f3b7d160f4df533808e95d0def5b6 Mon Sep 17 00:00:00 2001 From: Jing Ling Date: Mon, 31 Aug 2026 16:53:45 +0800 Subject: [PATCH 1/3] docs: add audit integration sample --- .gitignore | 1 + Ling.Audit.sln | 92 ++++++++++++ README.md | 10 ++ .../Ling.Audit.Sample.Contracts.csproj | 17 +++ samples/Ling.Audit.Sample.Contracts/Order.cs | 10 ++ .../Ling.Audit.Sample.csproj | 15 ++ samples/Ling.Audit.Sample/Program.cs | 131 ++++++++++++++++++ samples/README.md | 29 ++++ 8 files changed, 305 insertions(+) create mode 100644 samples/Ling.Audit.Sample.Contracts/Ling.Audit.Sample.Contracts.csproj create mode 100644 samples/Ling.Audit.Sample.Contracts/Order.cs create mode 100644 samples/Ling.Audit.Sample/Ling.Audit.Sample.csproj create mode 100644 samples/Ling.Audit.Sample/Program.cs create mode 100644 samples/README.md diff --git a/.gitignore b/.gitignore index 8a30d25..262bebf 100644 --- a/.gitignore +++ b/.gitignore @@ -265,6 +265,7 @@ ServiceFabricBackup/ *.mdf *.ldf *.ndf +*.db # Business Intelligence projects *.rdl.data diff --git a/Ling.Audit.sln b/Ling.Audit.sln index fbe94b1..0659697 100644 --- a/Ling.Audit.sln +++ b/Ling.Audit.sln @@ -31,40 +31,130 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "git", "git", "{02EA681E-C7D README.md = README.md EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{5D20AA90-6969-D8BD-9DCD-8634F4692FDA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ling.Audit.Sample.Contracts", "samples\Ling.Audit.Sample.Contracts\Ling.Audit.Sample.Contracts.csproj", "{843834D9-9D23-49A4-AC9B-908019A808FD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ling.Audit.Sample", "samples\Ling.Audit.Sample\Ling.Audit.Sample.csproj", "{B2BF7E2B-31C1-4CBA-9949-15CD2B4C0265}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {B1C735B7-5F67-4F65-9A5D-9E30B046934D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B1C735B7-5F67-4F65-9A5D-9E30B046934D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B1C735B7-5F67-4F65-9A5D-9E30B046934D}.Debug|x64.ActiveCfg = Debug|Any CPU + {B1C735B7-5F67-4F65-9A5D-9E30B046934D}.Debug|x64.Build.0 = Debug|Any CPU + {B1C735B7-5F67-4F65-9A5D-9E30B046934D}.Debug|x86.ActiveCfg = Debug|Any CPU + {B1C735B7-5F67-4F65-9A5D-9E30B046934D}.Debug|x86.Build.0 = Debug|Any CPU {B1C735B7-5F67-4F65-9A5D-9E30B046934D}.Release|Any CPU.ActiveCfg = Release|Any CPU {B1C735B7-5F67-4F65-9A5D-9E30B046934D}.Release|Any CPU.Build.0 = Release|Any CPU + {B1C735B7-5F67-4F65-9A5D-9E30B046934D}.Release|x64.ActiveCfg = Release|Any CPU + {B1C735B7-5F67-4F65-9A5D-9E30B046934D}.Release|x64.Build.0 = Release|Any CPU + {B1C735B7-5F67-4F65-9A5D-9E30B046934D}.Release|x86.ActiveCfg = Release|Any CPU + {B1C735B7-5F67-4F65-9A5D-9E30B046934D}.Release|x86.Build.0 = Release|Any CPU {ADF318B0-2EB4-405C-B93A-DC23346655C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {ADF318B0-2EB4-405C-B93A-DC23346655C9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ADF318B0-2EB4-405C-B93A-DC23346655C9}.Debug|x64.ActiveCfg = Debug|Any CPU + {ADF318B0-2EB4-405C-B93A-DC23346655C9}.Debug|x64.Build.0 = Debug|Any CPU + {ADF318B0-2EB4-405C-B93A-DC23346655C9}.Debug|x86.ActiveCfg = Debug|Any CPU + {ADF318B0-2EB4-405C-B93A-DC23346655C9}.Debug|x86.Build.0 = Debug|Any CPU {ADF318B0-2EB4-405C-B93A-DC23346655C9}.Release|Any CPU.ActiveCfg = Release|Any CPU {ADF318B0-2EB4-405C-B93A-DC23346655C9}.Release|Any CPU.Build.0 = Release|Any CPU + {ADF318B0-2EB4-405C-B93A-DC23346655C9}.Release|x64.ActiveCfg = Release|Any CPU + {ADF318B0-2EB4-405C-B93A-DC23346655C9}.Release|x64.Build.0 = Release|Any CPU + {ADF318B0-2EB4-405C-B93A-DC23346655C9}.Release|x86.ActiveCfg = Release|Any CPU + {ADF318B0-2EB4-405C-B93A-DC23346655C9}.Release|x86.Build.0 = Release|Any CPU {AD209C64-6C95-43A3-85CA-5EFDFF059DEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {AD209C64-6C95-43A3-85CA-5EFDFF059DEF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AD209C64-6C95-43A3-85CA-5EFDFF059DEF}.Debug|x64.ActiveCfg = Debug|Any CPU + {AD209C64-6C95-43A3-85CA-5EFDFF059DEF}.Debug|x64.Build.0 = Debug|Any CPU + {AD209C64-6C95-43A3-85CA-5EFDFF059DEF}.Debug|x86.ActiveCfg = Debug|Any CPU + {AD209C64-6C95-43A3-85CA-5EFDFF059DEF}.Debug|x86.Build.0 = Debug|Any CPU {AD209C64-6C95-43A3-85CA-5EFDFF059DEF}.Release|Any CPU.ActiveCfg = Release|Any CPU {AD209C64-6C95-43A3-85CA-5EFDFF059DEF}.Release|Any CPU.Build.0 = Release|Any CPU + {AD209C64-6C95-43A3-85CA-5EFDFF059DEF}.Release|x64.ActiveCfg = Release|Any CPU + {AD209C64-6C95-43A3-85CA-5EFDFF059DEF}.Release|x64.Build.0 = Release|Any CPU + {AD209C64-6C95-43A3-85CA-5EFDFF059DEF}.Release|x86.ActiveCfg = Release|Any CPU + {AD209C64-6C95-43A3-85CA-5EFDFF059DEF}.Release|x86.Build.0 = Release|Any CPU {49EC8F86-4D37-4880-B8C4-A9F49C4CA871}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {49EC8F86-4D37-4880-B8C4-A9F49C4CA871}.Debug|Any CPU.Build.0 = Debug|Any CPU + {49EC8F86-4D37-4880-B8C4-A9F49C4CA871}.Debug|x64.ActiveCfg = Debug|Any CPU + {49EC8F86-4D37-4880-B8C4-A9F49C4CA871}.Debug|x64.Build.0 = Debug|Any CPU + {49EC8F86-4D37-4880-B8C4-A9F49C4CA871}.Debug|x86.ActiveCfg = Debug|Any CPU + {49EC8F86-4D37-4880-B8C4-A9F49C4CA871}.Debug|x86.Build.0 = Debug|Any CPU {49EC8F86-4D37-4880-B8C4-A9F49C4CA871}.Release|Any CPU.ActiveCfg = Release|Any CPU {49EC8F86-4D37-4880-B8C4-A9F49C4CA871}.Release|Any CPU.Build.0 = Release|Any CPU + {49EC8F86-4D37-4880-B8C4-A9F49C4CA871}.Release|x64.ActiveCfg = Release|Any CPU + {49EC8F86-4D37-4880-B8C4-A9F49C4CA871}.Release|x64.Build.0 = Release|Any CPU + {49EC8F86-4D37-4880-B8C4-A9F49C4CA871}.Release|x86.ActiveCfg = Release|Any CPU + {49EC8F86-4D37-4880-B8C4-A9F49C4CA871}.Release|x86.Build.0 = Release|Any CPU {D168B363-6EFB-45D3-8BD8-BABADE073444}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D168B363-6EFB-45D3-8BD8-BABADE073444}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D168B363-6EFB-45D3-8BD8-BABADE073444}.Debug|x64.ActiveCfg = Debug|Any CPU + {D168B363-6EFB-45D3-8BD8-BABADE073444}.Debug|x64.Build.0 = Debug|Any CPU + {D168B363-6EFB-45D3-8BD8-BABADE073444}.Debug|x86.ActiveCfg = Debug|Any CPU + {D168B363-6EFB-45D3-8BD8-BABADE073444}.Debug|x86.Build.0 = Debug|Any CPU {D168B363-6EFB-45D3-8BD8-BABADE073444}.Release|Any CPU.ActiveCfg = Release|Any CPU {D168B363-6EFB-45D3-8BD8-BABADE073444}.Release|Any CPU.Build.0 = Release|Any CPU + {D168B363-6EFB-45D3-8BD8-BABADE073444}.Release|x64.ActiveCfg = Release|Any CPU + {D168B363-6EFB-45D3-8BD8-BABADE073444}.Release|x64.Build.0 = Release|Any CPU + {D168B363-6EFB-45D3-8BD8-BABADE073444}.Release|x86.ActiveCfg = Release|Any CPU + {D168B363-6EFB-45D3-8BD8-BABADE073444}.Release|x86.Build.0 = Release|Any CPU {05BEB921-D67B-4F40-9334-E176127F37C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {05BEB921-D67B-4F40-9334-E176127F37C0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {05BEB921-D67B-4F40-9334-E176127F37C0}.Debug|x64.ActiveCfg = Debug|Any CPU + {05BEB921-D67B-4F40-9334-E176127F37C0}.Debug|x64.Build.0 = Debug|Any CPU + {05BEB921-D67B-4F40-9334-E176127F37C0}.Debug|x86.ActiveCfg = Debug|Any CPU + {05BEB921-D67B-4F40-9334-E176127F37C0}.Debug|x86.Build.0 = Debug|Any CPU {05BEB921-D67B-4F40-9334-E176127F37C0}.Release|Any CPU.ActiveCfg = Release|Any CPU {05BEB921-D67B-4F40-9334-E176127F37C0}.Release|Any CPU.Build.0 = Release|Any CPU + {05BEB921-D67B-4F40-9334-E176127F37C0}.Release|x64.ActiveCfg = Release|Any CPU + {05BEB921-D67B-4F40-9334-E176127F37C0}.Release|x64.Build.0 = Release|Any CPU + {05BEB921-D67B-4F40-9334-E176127F37C0}.Release|x86.ActiveCfg = Release|Any CPU + {05BEB921-D67B-4F40-9334-E176127F37C0}.Release|x86.Build.0 = Release|Any CPU {7406F507-6A52-49B3-8F67-8E72BC6506E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7406F507-6A52-49B3-8F67-8E72BC6506E5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7406F507-6A52-49B3-8F67-8E72BC6506E5}.Debug|x64.ActiveCfg = Debug|Any CPU + {7406F507-6A52-49B3-8F67-8E72BC6506E5}.Debug|x64.Build.0 = Debug|Any CPU + {7406F507-6A52-49B3-8F67-8E72BC6506E5}.Debug|x86.ActiveCfg = Debug|Any CPU + {7406F507-6A52-49B3-8F67-8E72BC6506E5}.Debug|x86.Build.0 = Debug|Any CPU {7406F507-6A52-49B3-8F67-8E72BC6506E5}.Release|Any CPU.ActiveCfg = Release|Any CPU {7406F507-6A52-49B3-8F67-8E72BC6506E5}.Release|Any CPU.Build.0 = Release|Any CPU + {7406F507-6A52-49B3-8F67-8E72BC6506E5}.Release|x64.ActiveCfg = Release|Any CPU + {7406F507-6A52-49B3-8F67-8E72BC6506E5}.Release|x64.Build.0 = Release|Any CPU + {7406F507-6A52-49B3-8F67-8E72BC6506E5}.Release|x86.ActiveCfg = Release|Any CPU + {7406F507-6A52-49B3-8F67-8E72BC6506E5}.Release|x86.Build.0 = Release|Any CPU + {843834D9-9D23-49A4-AC9B-908019A808FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {843834D9-9D23-49A4-AC9B-908019A808FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {843834D9-9D23-49A4-AC9B-908019A808FD}.Debug|x64.ActiveCfg = Debug|Any CPU + {843834D9-9D23-49A4-AC9B-908019A808FD}.Debug|x64.Build.0 = Debug|Any CPU + {843834D9-9D23-49A4-AC9B-908019A808FD}.Debug|x86.ActiveCfg = Debug|Any CPU + {843834D9-9D23-49A4-AC9B-908019A808FD}.Debug|x86.Build.0 = Debug|Any CPU + {843834D9-9D23-49A4-AC9B-908019A808FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {843834D9-9D23-49A4-AC9B-908019A808FD}.Release|Any CPU.Build.0 = Release|Any CPU + {843834D9-9D23-49A4-AC9B-908019A808FD}.Release|x64.ActiveCfg = Release|Any CPU + {843834D9-9D23-49A4-AC9B-908019A808FD}.Release|x64.Build.0 = Release|Any CPU + {843834D9-9D23-49A4-AC9B-908019A808FD}.Release|x86.ActiveCfg = Release|Any CPU + {843834D9-9D23-49A4-AC9B-908019A808FD}.Release|x86.Build.0 = Release|Any CPU + {B2BF7E2B-31C1-4CBA-9949-15CD2B4C0265}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B2BF7E2B-31C1-4CBA-9949-15CD2B4C0265}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B2BF7E2B-31C1-4CBA-9949-15CD2B4C0265}.Debug|x64.ActiveCfg = Debug|Any CPU + {B2BF7E2B-31C1-4CBA-9949-15CD2B4C0265}.Debug|x64.Build.0 = Debug|Any CPU + {B2BF7E2B-31C1-4CBA-9949-15CD2B4C0265}.Debug|x86.ActiveCfg = Debug|Any CPU + {B2BF7E2B-31C1-4CBA-9949-15CD2B4C0265}.Debug|x86.Build.0 = Debug|Any CPU + {B2BF7E2B-31C1-4CBA-9949-15CD2B4C0265}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B2BF7E2B-31C1-4CBA-9949-15CD2B4C0265}.Release|Any CPU.Build.0 = Release|Any CPU + {B2BF7E2B-31C1-4CBA-9949-15CD2B4C0265}.Release|x64.ActiveCfg = Release|Any CPU + {B2BF7E2B-31C1-4CBA-9949-15CD2B4C0265}.Release|x64.Build.0 = Release|Any CPU + {B2BF7E2B-31C1-4CBA-9949-15CD2B4C0265}.Release|x86.ActiveCfg = Release|Any CPU + {B2BF7E2B-31C1-4CBA-9949-15CD2B4C0265}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -77,6 +167,8 @@ Global {D168B363-6EFB-45D3-8BD8-BABADE073444} = {BB2FED91-147D-47A5-9F12-87B30AF8B772} {05BEB921-D67B-4F40-9334-E176127F37C0} = {8572F9E1-6926-42F1-BE77-41EFE1775C40} {7406F507-6A52-49B3-8F67-8E72BC6506E5} = {8572F9E1-6926-42F1-BE77-41EFE1775C40} + {843834D9-9D23-49A4-AC9B-908019A808FD} = {5D20AA90-6969-D8BD-9DCD-8634F4692FDA} + {B2BF7E2B-31C1-4CBA-9949-15CD2B4C0265} = {5D20AA90-6969-D8BD-9DCD-8634F4692FDA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {523730A8-DA1E-4D7D-BF87-DB79B2F060F4} diff --git a/README.md b/README.md index 52871d6..fff2212 100644 --- a/README.md +++ b/README.md @@ -274,6 +274,16 @@ The former `Ling.EntityFrameworkCore.Audit` package was renamed to `Ling.Audit.E See the [2.0 migration guide](docs/migrating-to-2.0.md) for package, API, transaction, and data-format changes. +## Samples + +The repository includes a runnable ASP.NET Core Minimal API sample in [`samples/`](samples/). It combines `Ling.Audit`, `Ling.Audit.EntityFrameworkCore`, and `Ling.Audit.AspNetCore` with SQLite, and demonstrates authenticated user resolution, explicit transactions, soft deletion, and audit-log queries. + +```shell +dotnet run --project samples/Ling.Audit.Sample/Ling.Audit.Sample.csproj +``` + +See [`samples/README.md`](samples/README.md) for the request examples and production notes. + ## Development ```shell diff --git a/samples/Ling.Audit.Sample.Contracts/Ling.Audit.Sample.Contracts.csproj b/samples/Ling.Audit.Sample.Contracts/Ling.Audit.Sample.Contracts.csproj new file mode 100644 index 0000000..2b2e167 --- /dev/null +++ b/samples/Ling.Audit.Sample.Contracts/Ling.Audit.Sample.Contracts.csproj @@ -0,0 +1,17 @@ + + + + net9.0 + enable + enable + + + + + + + + diff --git a/samples/Ling.Audit.Sample.Contracts/Order.cs b/samples/Ling.Audit.Sample.Contracts/Order.cs new file mode 100644 index 0000000..e4ef927 --- /dev/null +++ b/samples/Ling.Audit.Sample.Contracts/Order.cs @@ -0,0 +1,10 @@ +using Ling.Audit; + +namespace Ling.Audit.Sample.Contracts; + +public sealed partial class Order : IFullAudited +{ + public int Id { get; set; } + + public string Description { get; set; } = string.Empty; +} diff --git a/samples/Ling.Audit.Sample/Ling.Audit.Sample.csproj b/samples/Ling.Audit.Sample/Ling.Audit.Sample.csproj new file mode 100644 index 0000000..eb7df58 --- /dev/null +++ b/samples/Ling.Audit.Sample/Ling.Audit.Sample.csproj @@ -0,0 +1,15 @@ + + + + net9.0 + enable + enable + + + + + + + + + diff --git a/samples/Ling.Audit.Sample/Program.cs b/samples/Ling.Audit.Sample/Program.cs new file mode 100644 index 0000000..7833246 --- /dev/null +++ b/samples/Ling.Audit.Sample/Program.cs @@ -0,0 +1,131 @@ +using System.Security.Claims; +using Ling.Audit.EntityFrameworkCore; +using Ling.Audit.Sample.Contracts; +using Ling.Audit.AspNetCore; +using Microsoft.EntityFrameworkCore; + +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddHttpContextAccessor(); + +builder.Services.AddDbContext(options => +{ + options.UseSqlite("Data Source=ling-audit-sample.db"); + options.UseAspNetCoreAudit( + audit => audit.MaxClientNameLength = 256, + audit => audit.TransactionMode = AuditTransactionMode.RequireExplicitTransaction); +}); + +var app = builder.Build(); + +// A real application would install authentication middleware here. The sample uses +// a deterministic principal so the generated audit records are easy to inspect. +app.Use(async (context, next) => +{ + var identity = new ClaimsIdentity( + [ + new Claim(ClaimTypes.NameIdentifier, "sample-user"), + new Claim(ClaimTypes.Name, "Sample User"), + ], + authenticationType: "Sample"); + context.User = new ClaimsPrincipal(identity); + + await next(context); +}); + +await using (var scope = app.Services.CreateAsyncScope()) +{ + var db = scope.ServiceProvider.GetRequiredService(); + await db.Database.EnsureCreatedAsync(); +} + +app.MapGet("/orders", async (SampleDbContext db, CancellationToken cancellationToken) => + await db.Orders + .Where(order => !order.IsDeleted) + .Select(order => new + { + order.Id, + order.Description, + order.CreatedAt, + order.CreatedBy, + order.LastModifiedAt, + order.LastModifiedBy, + }) + .ToListAsync(cancellationToken)); + +app.MapPost("/orders", async ( + CreateOrderRequest request, + SampleDbContext db, + CancellationToken cancellationToken) => +{ + await using var transaction = + await db.Database.BeginTransactionAsync(cancellationToken); + + var order = new Order { Description = request.Description }; + db.Orders.Add(order); + await db.SaveChangesAsync(cancellationToken); + await transaction.CommitAsync(cancellationToken); + + return Results.Created($"/orders/{order.Id}", new + { + order.Id, + order.Description, + order.CreatedAt, + order.CreatedBy, + }); +}); + +app.MapDelete("/orders/{id:int}", async ( + int id, + SampleDbContext db, + CancellationToken cancellationToken) => +{ + var order = await db.Orders.FindAsync([id], cancellationToken); + if (order is null) + { + return Results.NotFound(); + } + + await using var transaction = + await db.Database.BeginTransactionAsync(cancellationToken); + + db.Orders.Remove(order); + await db.SaveChangesAsync(cancellationToken); + await transaction.CommitAsync(cancellationToken); + + return Results.NoContent(); +}); + +app.MapGet("/audit", async (SampleDbContext db, CancellationToken cancellationToken) => + await db.EntityChanges + .OrderByDescending(change => change.Id) + .Select(change => new + { + change.Id, + change.EntityTypeName, + change.EntityKey, + change.EventType, + change.EventTime, + change.UserId, + change.UserName, + change.ClientName, + }) + .ToListAsync(cancellationToken)); + +app.Run(); + +public sealed record CreateOrderRequest(string Description); + +public sealed class SampleDbContext(DbContextOptions options) : DbContext(options) +{ + public DbSet Orders => Set(); + + public DbSet> EntityChanges => + Set>(); + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().IsAuditable(); + modelBuilder.SetupSoftDeleteQueryFilter(); + } +} diff --git a/samples/README.md b/samples/README.md new file mode 100644 index 0000000..c7a284c --- /dev/null +++ b/samples/README.md @@ -0,0 +1,29 @@ +# Ling.Audit sample + +This sample is a small ASP.NET Core Minimal API backed by SQLite. It demonstrates the three package layers working together: + +- `Ling.Audit.Sample.Contracts` references only `Ling.Audit` and implements `IFullAudited` on the `Order` entity; +- `Ling.Audit.Sample` references the EF Core and ASP.NET Core integrations; +- `UseAspNetCoreAudit` resolves the deterministic sample ClaimsPrincipal and writes the user, client, and timestamp fields; +- `RequireExplicitTransaction` makes the business save and audit-log save participate in the same transaction; +- deleting an order marks it as soft-deleted, so it disappears from the normal order query; +- `/audit` exposes the generated entity change logs for inspection. + +Run it from the repository root: + +```shell +dotnet run --project samples/Ling.Audit.Sample/Ling.Audit.Sample.csproj +``` + +Create an order and inspect its generated audit fields: + +```shell +curl -X POST http://localhost:5000/orders \ + -H "Content-Type: application/json" \ + -d '{"description":"First sample order"}' + +curl http://localhost:5000/orders +curl http://localhost:5000/audit +``` + +The sample uses `EnsureCreated` for simplicity. Production applications should create normal EF Core migrations after enabling auditing. From 37558027aaf12b546bdaa55129516793f767f43e Mon Sep 17 00:00:00 2001 From: Jing Ling Date: Mon, 31 Aug 2026 17:23:30 +0800 Subject: [PATCH 2/3] docs: tailor package readmes --- .../Ling.Audit.AspNetCore.csproj | 4 +- src/Ling.Audit.AspNetCore/README.md | 45 +++++++++++++++++ .../Ling.Audit.EntityFrameworkCore.csproj | 4 +- src/Ling.Audit.EntityFrameworkCore/README.md | 48 +++++++++++++++++++ src/Ling.Audit/README.md | 10 +++- 5 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 src/Ling.Audit.AspNetCore/README.md create mode 100644 src/Ling.Audit.EntityFrameworkCore/README.md diff --git a/src/Ling.Audit.AspNetCore/Ling.Audit.AspNetCore.csproj b/src/Ling.Audit.AspNetCore/Ling.Audit.AspNetCore.csproj index 6cffc89..247168e 100644 --- a/src/Ling.Audit.AspNetCore/Ling.Audit.AspNetCore.csproj +++ b/src/Ling.Audit.AspNetCore/Ling.Audit.AspNetCore.csproj @@ -1,4 +1,4 @@ - + net6.0;net7.0;net8.0;net9.0 @@ -23,7 +23,7 @@ - + diff --git a/src/Ling.Audit.AspNetCore/README.md b/src/Ling.Audit.AspNetCore/README.md new file mode 100644 index 0000000..72cf494 --- /dev/null +++ b/src/Ling.Audit.AspNetCore/README.md @@ -0,0 +1,45 @@ +# Ling.Audit.AspNetCore + +ASP.NET Core request-context integration for Ling.Audit.EntityFrameworkCore. + +This package resolves the current user from `HttpContext.User` and supplies user ID, user name, remote IP address, and a bounded client name to the EF Core audit pipeline. It does not invoke authentication itself. + +## Installation + +```shell +dotnet add package Ling.Audit.AspNetCore +``` + +## Quick start + +```csharp +builder.Services.AddDbContext(options => +{ + options.UseSqlServer(connectionString); + options.UseAspNetCoreAudit(http => + { + http.UserIdClaimType = "sub"; + http.UserNameClaimType = "name"; + http.MaxClientNameLength = 256; + }); +}); +``` + +The default principal resolver prefers explicit claim-type settings, then ASP.NET Core Identity claim settings, the authenticated identity's `Name`, and common `name identifier`/`sub` fallbacks. Register an `IAuditPrincipalResolver` when the application uses custom claims, multiple identities, or a non-standard selection rule. + +```csharp +public sealed class TenantPrincipalResolver : IAuditPrincipalResolver +{ + public AuditPrincipal Resolve(HttpContext context) => new( + context.User.FindFirst("employee_id")?.Value, + context.User.Identity?.Name); +} + +options.UseAspNetCoreAudit(); +``` + +The integration uses string user IDs. Applications using `Guid`, `int`, or another key type can configure `Ling.Audit.EntityFrameworkCore` directly with a matching user provider. + +## Related package + +This package depends on [Ling.Audit.EntityFrameworkCore](https://www.nuget.org/packages/Ling.Audit.EntityFrameworkCore), which provides the EF Core model configuration and audit persistence behavior. diff --git a/src/Ling.Audit.EntityFrameworkCore/Ling.Audit.EntityFrameworkCore.csproj b/src/Ling.Audit.EntityFrameworkCore/Ling.Audit.EntityFrameworkCore.csproj index c1781bd..6b4e046 100644 --- a/src/Ling.Audit.EntityFrameworkCore/Ling.Audit.EntityFrameworkCore.csproj +++ b/src/Ling.Audit.EntityFrameworkCore/Ling.Audit.EntityFrameworkCore.csproj @@ -1,4 +1,4 @@ - + net6.0;net7.0;net8.0;net9.0 @@ -19,7 +19,7 @@ - + diff --git a/src/Ling.Audit.EntityFrameworkCore/README.md b/src/Ling.Audit.EntityFrameworkCore/README.md new file mode 100644 index 0000000..2e96ec8 --- /dev/null +++ b/src/Ling.Audit.EntityFrameworkCore/README.md @@ -0,0 +1,48 @@ +# Ling.Audit.EntityFrameworkCore + +Entity Framework Core persistence integration for Ling.Audit. + +This package applies audit metadata during `SaveChanges`, maintains creation, modification, and deletion fields, records entity and field-level change logs, and provides soft-delete query filtering. + +## Installation + +```shell +dotnet add package Ling.Audit.EntityFrameworkCore +``` + +The package targets .NET 6.0 through .NET 9.0 and uses the matching EF Core major version. + +## Quick start + +```csharp +public sealed class AppDbContext(DbContextOptions options) : DbContext(options) +{ + public DbSet Orders => Set(); + public DbSet> EntityChanges => + Set>(); + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().IsAuditable(); + modelBuilder.SetupSoftDeleteQueryFilter(); + } +} + +services.AddDbContext(options => +{ + options.UseSqlServer(connectionString); + options.UseAudit(); +}); +``` + +Entities must be declared `partial` and implement one of the audit contracts from `Ling.Audit`, such as `ICreationAudited` or `IFullAudited`. The source generator supplies the matching properties at compile time. + +## User context and transactions + +Register an `AuditContextProviderBase` implementation to supply the current user, IP address, or client information. For ASP.NET Core request context integration, use [Ling.Audit.AspNetCore](https://www.nuget.org/packages/Ling.Audit.AspNetCore). + +When using `AuditTransactionMode.RequireExplicitTransaction`, wrap business changes in an explicit EF Core transaction so the business write and its audit records commit or roll back together. + +## Further reading + +See the [repository documentation](https://github.com/ling921/ling-audit) for migration notes, transaction behavior, and the runnable sample. diff --git a/src/Ling.Audit/README.md b/src/Ling.Audit/README.md index bb49e03..fc1e5f1 100644 --- a/src/Ling.Audit/README.md +++ b/src/Ling.Audit/README.md @@ -2,6 +2,14 @@ A source generator for automatically implementing audit properties in C# classes. +## Installation + +```shell +dotnet add package Ling.Audit +``` + +This package contains the audit contracts, attributes, analyzer, and source generator. It does not depend on Entity Framework Core or ASP.NET Core, so it can be used by domain and shared contract projects. + ## Basic Usage ```csharp @@ -95,4 +103,4 @@ public partial class Blog ## API Reference -For detailed API documentation, visit our [GitHub repository](https://github.com/ling921/ling-audit). +For persistence behavior, use [Ling.Audit.EntityFrameworkCore](https://www.nuget.org/packages/Ling.Audit.EntityFrameworkCore). For ASP.NET Core request context integration, use [Ling.Audit.AspNetCore](https://www.nuget.org/packages/Ling.Audit.AspNetCore). From aabd957ffca0f2178459d0b50cc3e3e8ebc3d923 Mon Sep 17 00:00:00 2001 From: Jing Ling Date: Tue, 1 Sep 2026 00:53:05 +0800 Subject: [PATCH 3/3] feat: add .NET 10 support --- .github/workflows/test.yml | 2 + README.md | 14 +++--- README.zh-CN.md | 14 +++--- src/Directory.Build.props | 2 +- .../Ling.Audit.AspNetCore.csproj | 2 +- .../Extensions/ModelBuilderExtensions.cs | 48 ++++++++++++++++++- .../Ling.Audit.EntityFrameworkCore.csproj | 7 ++- src/Ling.Audit.EntityFrameworkCore/README.md | 2 +- src/Ling.Audit/Ling.Audit.csproj | 6 +-- .../Ling.Audit.AspNetCore.Tests.csproj | 2 +- ...ing.Audit.EntityFrameworkCore.Tests.csproj | 5 +- .../V2/AuditIntegrationTests.cs | 4 ++ .../Ling.Audit.PackageConsumer.csproj | 4 +- .../AuditPropertyGeneratorTests.cs | 6 +-- 14 files changed, 87 insertions(+), 31 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f53445b..45df910 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -71,8 +71,10 @@ jobs: unzip -Z1 "$core" | grep -Fx 'lib/netstandard2.0/Ling.Audit.dll' unzip -Z1 "$efcore" | grep -Fx 'lib/net6.0/Ling.Audit.EntityFrameworkCore.dll' unzip -Z1 "$efcore" | grep -Fx 'lib/net9.0/Ling.Audit.EntityFrameworkCore.dll' + unzip -Z1 "$efcore" | grep -Fx 'lib/net10.0/Ling.Audit.EntityFrameworkCore.dll' unzip -Z1 "$aspnetcore" | grep -Fx 'lib/net6.0/Ling.Audit.AspNetCore.dll' unzip -Z1 "$aspnetcore" | grep -Fx 'lib/net9.0/Ling.Audit.AspNetCore.dll' + unzip -Z1 "$aspnetcore" | grep -Fx 'lib/net10.0/Ling.Audit.AspNetCore.dll' - name: Verify package consumption run: | diff --git a/README.md b/README.md index fff2212..ae4a21e 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ English | [简体中文](README.zh-CN.md) | Package | Purpose | Target frameworks | | --- | --- | --- | -| [`Ling.Audit`](https://www.nuget.org/packages/Ling.Audit/) [![NuGet](https://img.shields.io/nuget/v/Ling.Audit.svg)](https://www.nuget.org/packages/Ling.Audit/) | Audit contracts, source generator, analyzers, and code fixes. | .NET Standard 2.0/2.1, .NET Core 3.1, .NET 5–9 | -| [`Ling.Audit.EntityFrameworkCore`](https://www.nuget.org/packages/Ling.Audit.EntityFrameworkCore/) [![NuGet](https://img.shields.io/nuget/v/Ling.Audit.EntityFrameworkCore.svg)](https://www.nuget.org/packages/Ling.Audit.EntityFrameworkCore/) | Audit-property maintenance, soft deletion, and entity/field change logs. | .NET 6–9 | -| [`Ling.Audit.AspNetCore`](https://www.nuget.org/packages/Ling.Audit.AspNetCore/) [![NuGet](https://img.shields.io/nuget/v/Ling.Audit.AspNetCore.svg)](https://www.nuget.org/packages/Ling.Audit.AspNetCore/) | User, IP address, and client information from the current HTTP request. | .NET 6–9 | +| [`Ling.Audit`](https://www.nuget.org/packages/Ling.Audit/) [![NuGet](https://img.shields.io/nuget/v/Ling.Audit.svg)](https://www.nuget.org/packages/Ling.Audit/) | Audit contracts, source generator, analyzers, and code fixes. | .NET Standard 2.0 | +| [`Ling.Audit.EntityFrameworkCore`](https://www.nuget.org/packages/Ling.Audit.EntityFrameworkCore/) [![NuGet](https://img.shields.io/nuget/v/Ling.Audit.EntityFrameworkCore.svg)](https://www.nuget.org/packages/Ling.Audit.EntityFrameworkCore/) | Audit-property maintenance, soft deletion, and entity/field change logs. | .NET 6–10 | +| [`Ling.Audit.AspNetCore`](https://www.nuget.org/packages/Ling.Audit.AspNetCore/) [![NuGet](https://img.shields.io/nuget/v/Ling.Audit.AspNetCore.svg)](https://www.nuget.org/packages/Ling.Audit.AspNetCore/) | User, IP address, and client information from the current HTTP request. | .NET 6–10 | The EF Core and ASP.NET Core packages reference the matching EF Core major version for each target framework. @@ -32,7 +32,7 @@ The EF Core and ASP.NET Core packages reference the matching EF Core major versi Install the core package in the project that owns the entity types: ```shell -dotnet add package Ling.Audit --version 2.0.1 +dotnet add package Ling.Audit --version 2.1.0 ``` Implement the audit interface that matches the entity lifecycle. The type and every containing type must be `partial`: @@ -85,7 +85,7 @@ Use a basic interface for one value, or a composite interface for a complete lif Install the integration that matches the application's target framework: ```shell -dotnet add package Ling.Audit.EntityFrameworkCore --version 2.0.1 +dotnet add package Ling.Audit.EntityFrameworkCore --version 2.1.0 ``` Create a provider for the current user and client context: @@ -198,7 +198,7 @@ Global behavior can be changed with `AuditOptions.AllowAnonymous`, or customized For applications whose audit user ID is a string claim, install the ASP.NET Core package instead of configuring an EF user provider manually: ```shell -dotnet add package Ling.Audit.AspNetCore --version 2.0.1 +dotnet add package Ling.Audit.AspNetCore --version 2.1.0 ``` ```csharp @@ -291,7 +291,7 @@ dotnet build Ling.Audit.sln -c Release dotnet test Ling.Audit.sln -c Release ``` -The test matrix runs the EF Core and ASP.NET Core integration suites against .NET 6, 7, 8, and 9. Pull requests that change behavior should include corresponding tests. +The test matrix runs the EF Core and ASP.NET Core integration suites against .NET 6, 7, 8, 9, and 10. Pull requests that change behavior should include corresponding tests. ## License diff --git a/README.zh-CN.md b/README.zh-CN.md index 425b7ea..479ad9e 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -8,9 +8,9 @@ | 包 | 用途 | 目标框架 | | --- | --- | --- | -| [`Ling.Audit`](https://www.nuget.org/packages/Ling.Audit/) [![NuGet](https://img.shields.io/nuget/v/Ling.Audit.svg)](https://www.nuget.org/packages/Ling.Audit/) | 审计契约、源代码生成器、Analyzer 和 Code Fix。 | .NET Standard 2.0/2.1、.NET Core 3.1、.NET 5–9 | -| [`Ling.Audit.EntityFrameworkCore`](https://www.nuget.org/packages/Ling.Audit.EntityFrameworkCore/) [![NuGet](https://img.shields.io/nuget/v/Ling.Audit.EntityFrameworkCore.svg)](https://www.nuget.org/packages/Ling.Audit.EntityFrameworkCore/) | 审计属性维护、软删除以及实体/字段变更日志。 | .NET 6–9 | -| [`Ling.Audit.AspNetCore`](https://www.nuget.org/packages/Ling.Audit.AspNetCore/) [![NuGet](https://img.shields.io/nuget/v/Ling.Audit.AspNetCore.svg)](https://www.nuget.org/packages/Ling.Audit.AspNetCore/) | 从当前 HTTP 请求获取用户、IP 地址和客户端信息。 | .NET 6–9 | +| [`Ling.Audit`](https://www.nuget.org/packages/Ling.Audit/) [![NuGet](https://img.shields.io/nuget/v/Ling.Audit.svg)](https://www.nuget.org/packages/Ling.Audit/) | 审计契约、源代码生成器、Analyzer 和 Code Fix。 | .NET Standard 2.0 | +| [`Ling.Audit.EntityFrameworkCore`](https://www.nuget.org/packages/Ling.Audit.EntityFrameworkCore/) [![NuGet](https://img.shields.io/nuget/v/Ling.Audit.EntityFrameworkCore.svg)](https://www.nuget.org/packages/Ling.Audit.EntityFrameworkCore/) | 审计属性维护、软删除以及实体/字段变更日志。 | .NET 6–10 | +| [`Ling.Audit.AspNetCore`](https://www.nuget.org/packages/Ling.Audit.AspNetCore/) [![NuGet](https://img.shields.io/nuget/v/Ling.Audit.AspNetCore.svg)](https://www.nuget.org/packages/Ling.Audit.AspNetCore/) | 从当前 HTTP 请求获取用户、IP 地址和客户端信息。 | .NET 6–10 | EF Core 与 ASP.NET Core 包会为每个目标框架引用对应主版本的 EF Core。 @@ -32,7 +32,7 @@ EF Core 与 ASP.NET Core 包会为每个目标框架引用对应主版本的 EF 在定义实体的项目中安装核心包: ```shell -dotnet add package Ling.Audit --version 2.0.1 +dotnet add package Ling.Audit --version 2.1.0 ``` 根据实体生命周期实现相应审计接口。实体类型及其所有包含类型都必须是 `partial`: @@ -85,7 +85,7 @@ public sealed partial class Post 安装与应用目标框架相匹配的集成包: ```shell -dotnet add package Ling.Audit.EntityFrameworkCore --version 2.0.1 +dotnet add package Ling.Audit.EntityFrameworkCore --version 2.1.0 ``` 实现当前用户与客户端上下文提供器: @@ -198,7 +198,7 @@ public sealed partial class Registration : ICreationAudited 如果应用使用字符串 Claim 作为用户 ID,可以直接安装 ASP.NET Core 包,无需自行实现 EF 用户提供器: ```shell -dotnet add package Ling.Audit.AspNetCore --version 2.0.1 +dotnet add package Ling.Audit.AspNetCore --version 2.1.0 ``` ```csharp @@ -281,7 +281,7 @@ dotnet build Ling.Audit.sln -c Release dotnet test Ling.Audit.sln -c Release ``` -测试矩阵会在 .NET 6、7、8 和 9 上分别运行 EF Core 与 ASP.NET Core 集成测试。行为变更应同时包含相应测试。 +测试矩阵会在 .NET 6、7、8、9 和 10 上分别运行 EF Core 与 ASP.NET Core 集成测试。行为变更应同时包含相应测试。 ## 协议 diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 24e677f..b128d60 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -8,7 +8,7 @@ - 2.0.1 + 2.1.0 ling921 true diff --git a/src/Ling.Audit.AspNetCore/Ling.Audit.AspNetCore.csproj b/src/Ling.Audit.AspNetCore/Ling.Audit.AspNetCore.csproj index 247168e..1071f29 100644 --- a/src/Ling.Audit.AspNetCore/Ling.Audit.AspNetCore.csproj +++ b/src/Ling.Audit.AspNetCore/Ling.Audit.AspNetCore.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0;net8.0;net9.0 + net6.0;net7.0;net8.0;net9.0;net10.0 true $(NoWarn);IDE0130 Ling.Audit.AspNetCore diff --git a/src/Ling.Audit.EntityFrameworkCore/Extensions/ModelBuilderExtensions.cs b/src/Ling.Audit.EntityFrameworkCore/Extensions/ModelBuilderExtensions.cs index b92077a..f693cb3 100644 --- a/src/Ling.Audit.EntityFrameworkCore/Extensions/ModelBuilderExtensions.cs +++ b/src/Ling.Audit.EntityFrameworkCore/Extensions/ModelBuilderExtensions.cs @@ -34,7 +34,7 @@ public static void SetupSoftDeleteQueryFilter(this ModelBuilder builder) var propertyParameter = Expression.Property(typeParameter, Constants.IsDeleted); Expression body = Expression.Not(propertyParameter); - if (entityType.GetQueryFilter() is { } existingFilter) + if (GetExistingQueryFilter(entityType) is { } existingFilter) { var existingBody = new ReplacingExpressionVisitor( existingFilter.Parameters[0], @@ -44,7 +44,19 @@ public static void SetupSoftDeleteQueryFilter(this ModelBuilder builder) var lambda = Expression.Lambda(body, typeParameter); +#if NET10_0_OR_GREATER + var hasAnonymousFilter = entityType.GetDeclaredQueryFilters().Any(filter => filter.IsAnonymous); + if (hasAnonymousFilter) + { + builder.Entity(type).HasQueryFilter(lambda); + } + else + { + builder.Entity(type).HasQueryFilter("Ling.Audit.SoftDelete", lambda); + } +#else builder.Entity(type).HasQueryFilter(lambda); +#endif } } } @@ -336,6 +348,40 @@ internal static bool IsAuditable(this IReadOnlyAnnotatable annotatable) #endregion Internal Methods + private static LambdaExpression? GetExistingQueryFilter(IReadOnlyEntityType entityType) + { +#if NET10_0_OR_GREATER + var filters = entityType.GetDeclaredQueryFilters(); + if (filters.Count == 0) + { + return null; + } + + var expressions = filters + .Where(filter => filter.IsAnonymous) + .Select(filter => filter.Expression) + .OfType() + .ToArray(); + if (expressions.Length == 0) + { + return null; + } + + var parameter = expressions[0].Parameters[0]; + Expression body = expressions[0].Body; + foreach (var filter in expressions.Skip(1)) + { + var filterBody = new ReplacingExpressionVisitor(filter.Parameters[0], parameter) + .Visit(filter.Body)!; + body = Expression.AndAlso(body, filterBody); + } + + return Expression.Lambda(body, parameter); +#else + return entityType.GetQueryFilter(); +#endif + } + private sealed class ReplacingExpressionVisitor(Expression source, Expression target) : ExpressionVisitor { public override Expression? Visit(Expression? node) => diff --git a/src/Ling.Audit.EntityFrameworkCore/Ling.Audit.EntityFrameworkCore.csproj b/src/Ling.Audit.EntityFrameworkCore/Ling.Audit.EntityFrameworkCore.csproj index 6b4e046..10a245f 100644 --- a/src/Ling.Audit.EntityFrameworkCore/Ling.Audit.EntityFrameworkCore.csproj +++ b/src/Ling.Audit.EntityFrameworkCore/Ling.Audit.EntityFrameworkCore.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0;net8.0;net9.0 + net6.0;net7.0;net8.0;net9.0;net10.0 true $(NoWarn);IDE0130 Ling.Audit.EntityFrameworkCore @@ -43,6 +43,11 @@ + + + + + <_Parameter1>Ling.Audit.AspNetCore diff --git a/src/Ling.Audit.EntityFrameworkCore/README.md b/src/Ling.Audit.EntityFrameworkCore/README.md index 2e96ec8..21b0ccd 100644 --- a/src/Ling.Audit.EntityFrameworkCore/README.md +++ b/src/Ling.Audit.EntityFrameworkCore/README.md @@ -10,7 +10,7 @@ This package applies audit metadata during `SaveChanges`, maintains creation, mo dotnet add package Ling.Audit.EntityFrameworkCore ``` -The package targets .NET 6.0 through .NET 9.0 and uses the matching EF Core major version. +The package targets .NET 6.0 through .NET 10.0 and uses the matching EF Core major version. ## Quick start diff --git a/src/Ling.Audit/Ling.Audit.csproj b/src/Ling.Audit/Ling.Audit.csproj index 2aef56c..c17b430 100644 --- a/src/Ling.Audit/Ling.Audit.csproj +++ b/src/Ling.Audit/Ling.Audit.csproj @@ -1,17 +1,13 @@  - netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0;net9.0 + netstandard2.0 true .nuget true snupkg - - true - - Ling.Audit diff --git a/tests/Ling.Audit.AspNetCore.Tests/Ling.Audit.AspNetCore.Tests.csproj b/tests/Ling.Audit.AspNetCore.Tests/Ling.Audit.AspNetCore.Tests.csproj index c55088a..0adee52 100644 --- a/tests/Ling.Audit.AspNetCore.Tests/Ling.Audit.AspNetCore.Tests.csproj +++ b/tests/Ling.Audit.AspNetCore.Tests/Ling.Audit.AspNetCore.Tests.csproj @@ -1,7 +1,7 @@ - net6.0;net7.0;net8.0;net9.0 + net6.0;net7.0;net8.0;net9.0;net10.0 enable enable false diff --git a/tests/Ling.Audit.EntityFrameworkCore.Tests1/Ling.Audit.EntityFrameworkCore.Tests.csproj b/tests/Ling.Audit.EntityFrameworkCore.Tests1/Ling.Audit.EntityFrameworkCore.Tests.csproj index 7ce3f81..9fc5428 100644 --- a/tests/Ling.Audit.EntityFrameworkCore.Tests1/Ling.Audit.EntityFrameworkCore.Tests.csproj +++ b/tests/Ling.Audit.EntityFrameworkCore.Tests1/Ling.Audit.EntityFrameworkCore.Tests.csproj @@ -1,7 +1,7 @@  - net6.0;net7.0;net8.0;net9.0 + net6.0;net7.0;net8.0;net9.0;net10.0 enable enable false @@ -42,6 +42,9 @@ + + + diff --git a/tests/Ling.Audit.EntityFrameworkCore.Tests1/V2/AuditIntegrationTests.cs b/tests/Ling.Audit.EntityFrameworkCore.Tests1/V2/AuditIntegrationTests.cs index 72f1535..9ec9b9b 100644 --- a/tests/Ling.Audit.EntityFrameworkCore.Tests1/V2/AuditIntegrationTests.cs +++ b/tests/Ling.Audit.EntityFrameworkCore.Tests1/V2/AuditIntegrationTests.cs @@ -169,7 +169,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(builder => { builder.HasKey(x => x.Id); +#if NET10_0_OR_GREATER + builder.HasQueryFilter("TenantFilter", x => x.TenantId == 1); +#else builder.HasQueryFilter(x => x.TenantId == 1); +#endif }); modelBuilder.Entity().HasKey(x => x.Id); } diff --git a/tests/Ling.Audit.PackageConsumer/Ling.Audit.PackageConsumer.csproj b/tests/Ling.Audit.PackageConsumer/Ling.Audit.PackageConsumer.csproj index dbe3d98..bf00f2f 100644 --- a/tests/Ling.Audit.PackageConsumer/Ling.Audit.PackageConsumer.csproj +++ b/tests/Ling.Audit.PackageConsumer/Ling.Audit.PackageConsumer.csproj @@ -2,14 +2,14 @@ Exe - net9.0 + net10.0 enable enable ..\..\artifacts\package-consumer-final - + diff --git a/tests/Ling.Audit.SourceGenerators.Tests/AuditPropertyGeneratorTests.cs b/tests/Ling.Audit.SourceGenerators.Tests/AuditPropertyGeneratorTests.cs index e020100..9fd7d3f 100644 --- a/tests/Ling.Audit.SourceGenerators.Tests/AuditPropertyGeneratorTests.cs +++ b/tests/Ling.Audit.SourceGenerators.Tests/AuditPropertyGeneratorTests.cs @@ -24,7 +24,7 @@ public partial class GlobalEntity : IHasCreator, IHasCreationTime #pragma warning disable #nullable enable annotations - [global::System.CodeDom.Compiler.GeneratedCode("Ling.Audit.SourceGenerators", "2.0.1")] + [global::System.CodeDom.Compiler.GeneratedCode("Ling.Audit.SourceGenerators", "2.1.0")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] partial class GlobalEntity { @@ -61,7 +61,7 @@ public partial class SecondEntity : ISoftDelete { } namespace Test { - [global::System.CodeDom.Compiler.GeneratedCode("Ling.Audit.SourceGenerators", "2.0.1")] + [global::System.CodeDom.Compiler.GeneratedCode("Ling.Audit.SourceGenerators", "2.1.0")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] partial class FirstEntity { @@ -80,7 +80,7 @@ partial class FirstEntity namespace Test { - [global::System.CodeDom.Compiler.GeneratedCode("Ling.Audit.SourceGenerators", "2.0.1")] + [global::System.CodeDom.Compiler.GeneratedCode("Ling.Audit.SourceGenerators", "2.1.0")] [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage] partial class SecondEntity {