-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from WeihanLi/dev
9.1.0 preview 1
- Loading branch information
Showing
25 changed files
with
459 additions
and
149 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Release | ||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [ master ] | ||
jobs: | ||
build: | ||
name: Release | ||
runs-on: windows-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup .NET SDK | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: 9.0.x | ||
- name: Build | ||
shell: pwsh | ||
run: .\build.ps1 --stable=true | ||
- name: Get Release Version | ||
shell: pwsh | ||
run: dotnet-exec https://github.com/OpenReservation/scripts/blob/main/build/export-gh-release-version.cs | ||
- name: create release | ||
shell: pwsh | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
gh release create ${{ env.ReleaseVersion }} --generate-notes --target master (Get-Item ./artifacts/packages/*.nupkg) |
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
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 was deleted.
Oops, something went wrong.
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
Binary file not shown.
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
75 changes: 75 additions & 0 deletions
75
samples/WeihanLi.EntityFramework.Sample/DbContextInterceptorSamples.cs
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,75 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Diagnostics; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using WeihanLi.Extensions; | ||
|
||
namespace WeihanLi.EntityFramework.Sample; | ||
|
||
public static class DbContextInterceptorSamples | ||
{ | ||
public static async Task RunAsync() | ||
{ | ||
await InterceptorTest2(); | ||
} | ||
|
||
private static async Task InterceptorTest1() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddScoped<SavingInterceptor>(); | ||
services.AddDbContext<FileTestDbContext>((provider, options) => | ||
{ | ||
options.AddInterceptors(provider.GetRequiredService<SavingInterceptor>()); | ||
options.UseInMemoryDatabase("test"); | ||
}); | ||
await using var provider = services.BuildServiceProvider(); | ||
using var scope = provider.CreateScope(); | ||
var dbContext = scope.ServiceProvider.GetRequiredService<FileTestDbContext>(); | ||
await dbContext.Database.EnsureCreatedAsync(); | ||
dbContext.Entities.Add(new TestEntity { Id = 1, Name = "1" }); | ||
await dbContext.SaveChangesAsync(); | ||
} | ||
|
||
private static async Task InterceptorTest2() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddDbContext<FileTestDbContext>(options => | ||
{ | ||
options.UseInMemoryDatabase("test"); | ||
}); | ||
services.AddDbContextInterceptor<FileTestDbContext, SavingInterceptor>(); | ||
await using var provider = services.BuildServiceProvider(); | ||
using var scope = provider.CreateScope(); | ||
var dbContext = scope.ServiceProvider.GetRequiredService<FileTestDbContext>(); | ||
await dbContext.Database.EnsureCreatedAsync(); | ||
dbContext.Entities.Add(new TestEntity { Id = 2, Name = "1" }); | ||
await dbContext.SaveChangesAsync(); | ||
} | ||
} | ||
|
||
file sealed class FileTestDbContext(DbContextOptions<FileTestDbContext> options) : DbContext(options) | ||
{ | ||
public DbSet<TestEntity> Entities { get; set; } | ||
} | ||
|
||
file sealed class TestEntity | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
Check warning on line 57 in samples/WeihanLi.EntityFramework.Sample/DbContextInterceptorSamples.cs GitHub Actions / build
Check warning on line 57 in samples/WeihanLi.EntityFramework.Sample/DbContextInterceptorSamples.cs GitHub Actions / build
Check warning on line 57 in samples/WeihanLi.EntityFramework.Sample/DbContextInterceptorSamples.cs GitHub Actions / build
Check warning on line 57 in samples/WeihanLi.EntityFramework.Sample/DbContextInterceptorSamples.cs GitHub Actions / build
|
||
} | ||
|
||
file sealed class SavingInterceptor : SaveChangesInterceptor | ||
{ | ||
public override ValueTask<InterceptionResult<int>> SavingChangesAsync(DbContextEventData eventData, InterceptionResult<int> result, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
Console.WriteLine("SavingChangesAsync"); | ||
return base.SavingChangesAsync(eventData, result, cancellationToken); | ||
} | ||
|
||
public override ValueTask<int> SavedChangesAsync(SaveChangesCompletedEventData eventData, int result, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
Console.WriteLine("SavedChangesAsync"); | ||
return base.SavedChangesAsync(eventData, result, cancellationToken); | ||
} | ||
} |
Oops, something went wrong.