Skip to content

Scaffolding: not adding HasTrigger #30253

Closed as duplicate
Closed as duplicate

Description

@lsiepel

According to ErikEJ/EFCorePowerTools#1688 i should raise this issue here. When using the EFCorePowerTools the scaffolding does not detect/pick-up a trigger resulting in the absence of HasTrigger when creating the model.

DB schema in SQL server: https://1drv.ms/u/s!AnMcxmvEeupwjqVc431dzHgq-GUX6Q?e=zzLDvA
Contains three tables:
Gebruikersgroep and Autorisatieonderdeel both holding a trigger that performs actions against table Autorisatie

Versions:
EF Core version in use: EF Core 7.0.2
Is Handlebars used: yes
Is T4 used: no
Is .dacpac used: no
EF Core Power Tools version: 2.5.1277
Database engine: SQL Server
Visual Studio version: Visual Studio 2022
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET 6.0)

Activity

  1. roji commented on Feb 10, 2023

    @roji
    Member

    Duplicate of #10770

  2. roji commented on Feb 10, 2023

    @roji
    Member

    Although EF has infrastructure for managing triggers, it doesn't yet actually support them for SQL Server/SQLite. #10770 tracks that.

  3. ErikEJ commented on Feb 10, 2023

    @ErikEJ
    Contributor

    @roji this is about reverse engineering, not migrations

  4. roji commented on Feb 10, 2023

    @roji
    Member

    Sure, but i think we'd do both in the same work item, that's pretty standard. But no objection to track separately.

  5. ErikEJ commented on Feb 10, 2023

    @ErikEJ
    Contributor

    But scaffolding already attempts to Detect triggers AFAIK.

    So I think this an edge case of side effects from a trigger.

  6. lsiepel commented on Feb 14, 2023

    @lsiepel
    Author

    Don't think this is a duplicate, as to me it is a bug to an existing scaffolding feature, the linked issue is about adding a feature to migration. imho they might be related, but not a duplicate.

  7. ajcvickers commented on Feb 16, 2023

    @ajcvickers
    Contributor

    @lsiepel I am not able to reproduce this. With that schema, I get the following model configuration. It includes HasTrigger calls for both triggers in the model. Can you post the complete command line you are using, the verbose output from running the tool, and the generated configuration code?

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Autorisatie>(entity =>
        {
            entity.HasKey(e => e.IdAutorisatie).HasName("PK_Autorisatie_idAutorisatie");
    
            entity.ToTable("Autorisatie");
    
            entity.HasIndex(e => new { e.AutorisatieOnderdeelId, e.GebruikersgroepId }, "UQ_AutorisatieOnderdeel_Gerbuikersgroep").IsUnique();
    
            entity.Property(e => e.IdAutorisatie).HasColumnName("idAutorisatie");
    
            entity.HasOne(d => d.AutorisatieOnderdeel).WithMany(p => p.Autorisaties)
                .HasForeignKey(d => d.AutorisatieOnderdeelId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_Autorisatie_idAutorisatieOnderdeel");
    
            entity.HasOne(d => d.Gebruikersgroep).WithMany(p => p.Autorisaties)
                .HasForeignKey(d => d.GebruikersgroepId)
                .HasConstraintName("FK_Autorisatie_idGebruikersgroep");
        });
    
        modelBuilder.Entity<AutorisatieOnderdeel>(entity =>
        {
            entity.HasKey(e => e.IdAutorisatieOnderdeel).HasName("PK_Rol_idRol");
    
            entity.ToTable("AutorisatieOnderdeel", tb => tb.HasTrigger("TRG_AutorisatieOnderdeel_insert"));
    
            entity.HasIndex(e => e.IdAutorisatieOnderdeel, "UQ_AutorisatieOnderdeel_Naam").IsUnique();
    
            entity.Property(e => e.IdAutorisatieOnderdeel).HasColumnName("idAutorisatieOnderdeel");
            entity.Property(e => e.Naam)
                .HasMaxLength(40)
                .IsUnicode(false);
        });
    
        modelBuilder.Entity<Gebruikersgroep>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_Gebruikersgroep_idRolgroep");
    
            entity.ToTable("Gebruikersgroep", tb => tb.HasTrigger("TRG_Gebruikersgroep_insert"));
    
            entity.HasIndex(e => e.Naam, "UQ_Gebruikersgroep_Naam").IsUnique();
    
            entity.Property(e => e.Naam)
                .HasMaxLength(25)
                .IsUnicode(false);
        });
    
        OnModelCreatingPartial(modelBuilder);
    }
  8. ajcvickers commented on Mar 8, 2023

    @ajcvickers
    Contributor

    EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

    BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions