Skip to content

Commit 7d6b2f6

Browse files
authored
Merge pull request #14 from koenbeuk/fixed-recursive-triggers
Fixed recursive triggers
2 parents 8309082 + 24c835e commit 7d6b2f6

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

samples/1 - HelloWorld/1 - HelloWorld.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="EntityFrameworkCore.Triggered" Version="0.2.0" />
11+
<PackageReference Include="EntityFrameworkCore.Triggered" Version="0.2.1" />
1212
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.6" />
1313
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.6" />
1414
</ItemGroup>

samples/2 - PrimarySchool/2 - PrimarySchool.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="EntityFrameworkCore.Triggered" Version="0.2.0" />
11+
<PackageReference Include="EntityFrameworkCore.Triggered" Version="0.2.1" />
1212
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.6" />
13-
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.6" />
13+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.6" />
1414
</ItemGroup>
1515

1616
</Project>

samples/2 - PrimarySchool/Program.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,25 @@ class Program
1111
{
1212
static void Main(string[] args)
1313
{
14+
IServiceScope serviceScope = null;
15+
1416
var serviceProvider = new ServiceCollection()
15-
.AddLogging()
1617
.AddDbContext<ApplicationContext>(options => {
1718
options
18-
.UseInMemoryDatabase("ElementarySchool")
19-
.UseTriggers();
19+
.UseSqlite("Data source=test.db")
20+
.UseTriggers(triggerOptions => {
21+
triggerOptions.UseApplicationScopedServiceProviderAccessor(_ => serviceScope.ServiceProvider);
22+
});
2023
})
2124
.AddScoped<IBeforeSaveTrigger<Student>, Triggers.StudentSignupToMandatoryCourses>()
2225
.BuildServiceProvider();
2326

24-
var applicationContext = serviceProvider.GetRequiredService<ApplicationContext>();
27+
serviceScope = serviceProvider.CreateScope();
28+
29+
var applicationContext = serviceScope.ServiceProvider.GetRequiredService<ApplicationContext>();
30+
31+
applicationContext.Database.EnsureDeleted();
32+
applicationContext.Database.EnsureCreated();
2533

2634
applicationContext.Courses.Add(new Course {
2735
Id = 1,

samples/3 - StudentManagerAspNetCore/3 - StudentManagerAspNetCore.csproj

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,9 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<None Remove="TestDatabase.db" />
11-
</ItemGroup>
12-
13-
<ItemGroup>
14-
<PackageReference Include="EntityFrameworkCore.Triggered" Version="0.2.0" />
10+
<PackageReference Include="EntityFrameworkCore.Triggered" Version="0.2.1" />
1511
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.6" />
1612
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.6" />
17-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.6">
18-
<PrivateAssets>all</PrivateAssets>
19-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20-
</PackageReference>
21-
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
2213
</ItemGroup>
2314

2415
</Project>

samples/3 - StudentManagerAspNetCore/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void ConfigureServices(IServiceCollection services)
3333
services
3434
.AddDbContext<ApplicationContext>(options => {
3535
options
36-
.UseSqlite("Data source=TestDatabase.db")
36+
.UseSqlite("Data source=test.db")
3737
.UseTriggers();
3838
})
3939
.AddScoped<IBeforeSaveTrigger<Course>, Triggers.CourseAutoSignupStudents>()

src/EntityFrameworkCore.Triggered/Internal/RecursiveTriggerContextDiscoveryStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public IEnumerable<ITriggerContextDescriptor> Discover(TriggerOptions options, T
4747
// In case someone made a call to TriggerSession.DetectChanges, prior to calling RaiseBeforeSaveTriggers, we want to make sure that we include that discovery result in the first iteration
4848
if (iteration == 0)
4949
{
50-
changes = tracker.DiscoveredChanges!;
50+
changes = tracker.DiscoveredChanges.ToList();
5151
}
5252

5353
if (changes.Any())

0 commit comments

Comments
 (0)