diff --git a/src/EFCore.Design/Scaffolding/Internal/RelationalScaffoldingModelFactory.cs b/src/EFCore.Design/Scaffolding/Internal/RelationalScaffoldingModelFactory.cs index 63fc1fee6bc..4ba7d5fd64f 100644 --- a/src/EFCore.Design/Scaffolding/Internal/RelationalScaffoldingModelFactory.cs +++ b/src/EFCore.Design/Scaffolding/Internal/RelationalScaffoldingModelFactory.cs @@ -335,9 +335,9 @@ protected virtual ModelBuilder VisitTables(ModelBuilder modelBuilder, ICollectio VisitUniqueConstraints(builder, table.UniqueConstraints); VisitIndexes(builder, table.Indexes); - foreach (var triggerName in table.Triggers) + foreach (var trigger in table.Triggers) { - builder.ToTable(table.Name, table.Schema, tb => tb.HasTrigger(triggerName)); + builder.ToTable(table.Name, table.Schema, tb => tb.HasTrigger(trigger.Name)); } builder.Metadata.AddAnnotations(table.GetAnnotations()); diff --git a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseTable.cs b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseTable.cs index 7c00b873ac2..88ecb427189 100644 --- a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseTable.cs +++ b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseTable.cs @@ -60,7 +60,7 @@ public class DatabaseTable : Annotatable /// /// The list of triggers defined on the table. /// - public virtual HashSet Triggers { get; } = new HashSet(); + public virtual IList Triggers { get; } = new List(); /// public override string ToString() diff --git a/src/EFCore.Relational/Scaffolding/Metadata/DatabaseTrigger.cs b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseTrigger.cs new file mode 100644 index 00000000000..d7a76f51cd6 --- /dev/null +++ b/src/EFCore.Relational/Scaffolding/Metadata/DatabaseTrigger.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace Microsoft.EntityFrameworkCore.Scaffolding.Metadata; + +/// +/// A simple model for a database trigger used when reverse engineering an existing database. +/// +/// +/// See Reverse engineering (scaffolding) an existing database, and +/// EF Core design-time services for more information and examples. +/// +public class DatabaseTrigger : Annotatable +{ + /// + /// The trigger name. + /// + public virtual string Name { get; set; } = null!; +} diff --git a/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs b/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs index afffd6067b7..e2a5e92ec5f 100644 --- a/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs +++ b/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs @@ -1330,7 +1330,7 @@ FROM [sys].[triggers] AS [tr] // We don't actually scaffold anything beyond the fact that there's a trigger with a given name. // This is to modify the SaveChanges logic to not use OUTPUT without INTO, which is incompatible with triggers. - table.Triggers.Add(triggerName); + table.Triggers.Add(new DatabaseTrigger { Name = triggerName }); } } } diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/SqlServerDatabaseModelFactoryTest.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/SqlServerDatabaseModelFactoryTest.cs index b0d07cd1c9b..3c8a04f7f5a 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/SqlServerDatabaseModelFactoryTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/SqlServerDatabaseModelFactoryTest.cs @@ -914,9 +914,9 @@ AFTER INSERT AS var table = dbModel.Tables.Single(); var triggers = table.Triggers; - Assert.Collection(triggers.OrderBy(t => t), - t => Assert.Equal("Trigger1", t), - t => Assert.Equal("Trigger2", t)); + Assert.Collection(triggers.OrderBy(t => t.Name), + t => Assert.Equal("Trigger1", t.Name), + t => Assert.Equal("Trigger2", t.Name)); }, "DROP TABLE SomeTable;");