Skip to content

Commit 23fcd43

Browse files
authored
Merge pull request #71 from WeihanLi/dev
9.1.0
2 parents 579e2fa + 0a4170f commit 23fcd43

15 files changed

+399
-100
lines changed

Directory.Build.props

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<Project>
2-
<Import Project="./build/sign.props" />
32
<Import Project="./build/version.props" />
43

54
<PropertyGroup>
65
<TargetFramework>net9.0</TargetFramework>
76
<LangVersion>preview</LangVersion>
87
<ImplicitUsings>enable</ImplicitUsings>
98
<Nullable>enable</Nullable>
10-
<CommonVersion>1.0.72</CommonVersion>
11-
<EFVersion>9.0.0</EFVersion>
9+
<CommonVersion>1.0.74</CommonVersion>
10+
<EFVersion>9.0.1</EFVersion>
1211

1312
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1413
<EmbedUntrackedSources>true</EmbedUntrackedSources>
@@ -21,6 +20,6 @@
2120
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
2221
<RepositoryUrl>https://github.com/WeihanLi/WeihanLi.EntityFramework</RepositoryUrl>
2322
<RepositoryType>git</RepositoryType>
24-
<Copyright>Copyright 2019-2024 (c) WeihanLi</Copyright>
23+
<Copyright>Copyright 2019-$([System.DateTime]::Now.Year) (c) WeihanLi</Copyright>
2524
</PropertyGroup>
2625
</Project>

WeihanLi.EntityFramework.sln

+15
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WeihanLi.EntityFramework.Te
1515
EndProject
1616
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{A1756F80-F25E-4ADC-A079-048FFCA5DBA6}"
1717
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WeihanLi.EntityFramework.SourceGenerator", "src\WeihanLi.EntityFramework.SourceGenerator\WeihanLi.EntityFramework.SourceGenerator.csproj", "{010A98BE-1871-4E6F-8129-7A1C44C73423}"
19+
EndProject
1820
Global
1921
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2022
Debug|Any CPU = Debug|Any CPU
@@ -61,6 +63,18 @@ Global
6163
{9DF6D464-63A7-487C-9763-4A212ADDFC4B}.Release|x64.Build.0 = Release|Any CPU
6264
{9DF6D464-63A7-487C-9763-4A212ADDFC4B}.Release|x86.ActiveCfg = Release|Any CPU
6365
{9DF6D464-63A7-487C-9763-4A212ADDFC4B}.Release|x86.Build.0 = Release|Any CPU
66+
{010A98BE-1871-4E6F-8129-7A1C44C73423}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
67+
{010A98BE-1871-4E6F-8129-7A1C44C73423}.Debug|Any CPU.Build.0 = Debug|Any CPU
68+
{010A98BE-1871-4E6F-8129-7A1C44C73423}.Debug|x64.ActiveCfg = Debug|Any CPU
69+
{010A98BE-1871-4E6F-8129-7A1C44C73423}.Debug|x64.Build.0 = Debug|Any CPU
70+
{010A98BE-1871-4E6F-8129-7A1C44C73423}.Debug|x86.ActiveCfg = Debug|Any CPU
71+
{010A98BE-1871-4E6F-8129-7A1C44C73423}.Debug|x86.Build.0 = Debug|Any CPU
72+
{010A98BE-1871-4E6F-8129-7A1C44C73423}.Release|Any CPU.ActiveCfg = Release|Any CPU
73+
{010A98BE-1871-4E6F-8129-7A1C44C73423}.Release|Any CPU.Build.0 = Release|Any CPU
74+
{010A98BE-1871-4E6F-8129-7A1C44C73423}.Release|x64.ActiveCfg = Release|Any CPU
75+
{010A98BE-1871-4E6F-8129-7A1C44C73423}.Release|x64.Build.0 = Release|Any CPU
76+
{010A98BE-1871-4E6F-8129-7A1C44C73423}.Release|x86.ActiveCfg = Release|Any CPU
77+
{010A98BE-1871-4E6F-8129-7A1C44C73423}.Release|x86.Build.0 = Release|Any CPU
6478
EndGlobalSection
6579
GlobalSection(SolutionProperties) = preSolution
6680
HideSolutionNode = FALSE
@@ -69,6 +83,7 @@ Global
6983
{0BB1C3F3-50C6-4924-894C-0A9A7BA4E54A} = {40B7673F-5ACD-42E4-AE04-6C3AEEBC8546}
7084
{0E013C55-6D52-4B68-B188-460B97DB1E48} = {46AED92E-94FC-409A-9CFB-C9CD4E59717D}
7185
{9DF6D464-63A7-487C-9763-4A212ADDFC4B} = {A1756F80-F25E-4ADC-A079-048FFCA5DBA6}
86+
{010A98BE-1871-4E6F-8129-7A1C44C73423} = {40B7673F-5ACD-42E4-AE04-6C3AEEBC8546}
7287
EndGlobalSection
7388
GlobalSection(ExtensibilityGlobals) = postSolution
7489
SolutionGuid = {201A8B4F-A16D-44B7-BB29-F9B9CFC2A467}

build/sign.props

-7
This file was deleted.

build/version.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<PropertyGroup>
33
<VersionMajor>9</VersionMajor>
4-
<VersionMinor>0</VersionMinor>
4+
<VersionMinor>1</VersionMinor>
55
<VersionPatch>0</VersionPatch>
66
<VersionRevision>0</VersionRevision>
77
<VersionPrefix Condition="'$(VersionRevision)'=='0' or '$(VersionRevision)'==''">$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>

build/weihanli.snk

-596 Bytes
Binary file not shown.

samples/WeihanLi.EntityFramework.Sample/AutoAuditContext1.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ namespace WeihanLi.EntityFramework.Sample;
66
public class AutoAuditContext1(DbContextOptions dbContextOptions, IServiceProvider serviceProvider)
77
: AuditDbContext(dbContextOptions, serviceProvider)
88
{
9-
public DbSet<TestJobEntity> Jobs { get; set; }
9+
public DbSet<TestJobEntity> Jobs { get; set; } = null!;
1010
}
1111

1212

1313
public class AutoAuditContext2(DbContextOptions<AutoAuditContext2> options) : DbContext(options)
1414
{
15-
public DbSet<TestJobEntity> Jobs { get; set; }
15+
public DbSet<TestJobEntity> Jobs { get; set; } = null!;
1616
}
1717

1818
public class TestJobEntity
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using Microsoft.EntityFrameworkCore.Diagnostics;
3+
using Microsoft.Extensions.DependencyInjection;
4+
using WeihanLi.Extensions;
5+
6+
namespace WeihanLi.EntityFramework.Sample;
7+
8+
public static class DbContextInterceptorSamples
9+
{
10+
public static async Task RunAsync()
11+
{
12+
await InterceptorTest2();
13+
}
14+
15+
private static async Task InterceptorTest1()
16+
{
17+
var services = new ServiceCollection();
18+
services.AddScoped<SavingInterceptor>();
19+
services.AddDbContext<FileTestDbContext>((provider, options) =>
20+
{
21+
options.AddInterceptors(provider.GetRequiredService<SavingInterceptor>());
22+
options.UseInMemoryDatabase("test");
23+
});
24+
await using var provider = services.BuildServiceProvider();
25+
using var scope = provider.CreateScope();
26+
var dbContext = scope.ServiceProvider.GetRequiredService<FileTestDbContext>();
27+
await dbContext.Database.EnsureCreatedAsync();
28+
dbContext.Entities.Add(new TestEntity { Id = 1, Name = "1" });
29+
await dbContext.SaveChangesAsync();
30+
}
31+
32+
private static async Task InterceptorTest2()
33+
{
34+
var services = new ServiceCollection();
35+
services.AddDbContext<FileTestDbContext>(options =>
36+
{
37+
options.UseInMemoryDatabase("test");
38+
});
39+
services.AddDbContextInterceptor<FileTestDbContext, SavingInterceptor>();
40+
await using var provider = services.BuildServiceProvider();
41+
using var scope = provider.CreateScope();
42+
var dbContext = scope.ServiceProvider.GetRequiredService<FileTestDbContext>();
43+
await dbContext.Database.EnsureCreatedAsync();
44+
dbContext.Entities.Add(new TestEntity { Id = 2, Name = "1" });
45+
await dbContext.SaveChangesAsync();
46+
}
47+
}
48+
49+
file sealed class FileTestDbContext(DbContextOptions<FileTestDbContext> options) : DbContext(options)
50+
{
51+
public DbSet<TestEntity> Entities { get; set; }
52+
}
53+
54+
file sealed class TestEntity
55+
{
56+
public int Id { get; set; }
57+
public string Name { get; set; }
58+
}
59+
60+
file sealed class SavingInterceptor : SaveChangesInterceptor
61+
{
62+
public override ValueTask<InterceptionResult<int>> SavingChangesAsync(DbContextEventData eventData, InterceptionResult<int> result,
63+
CancellationToken cancellationToken = default)
64+
{
65+
Console.WriteLine("SavingChangesAsync");
66+
return base.SavingChangesAsync(eventData, result, cancellationToken);
67+
}
68+
69+
public override ValueTask<int> SavedChangesAsync(SaveChangesCompletedEventData eventData, int result,
70+
CancellationToken cancellationToken = default)
71+
{
72+
Console.WriteLine("SavedChangesAsync");
73+
return base.SavedChangesAsync(eventData, result, cancellationToken);
74+
}
75+
}

0 commit comments

Comments
 (0)