Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaffolding: not adding HasTrigger #30253

Closed
lsiepel opened this issue Feb 10, 2023 · 8 comments
Closed

Scaffolding: not adding HasTrigger #30253

lsiepel opened this issue Feb 10, 2023 · 8 comments

Comments

@lsiepel
Copy link

lsiepel commented Feb 10, 2023

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)

@roji
Copy link
Member

roji commented Feb 10, 2023

Duplicate of #10770

@roji roji marked this as a duplicate of #10770 Feb 10, 2023
@roji
Copy link
Member

roji commented Feb 10, 2023

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

@ErikEJ
Copy link
Contributor

ErikEJ commented Feb 10, 2023

@roji this is about reverse engineering, not migrations

@roji
Copy link
Member

roji commented Feb 10, 2023

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

@ErikEJ
Copy link
Contributor

ErikEJ commented Feb 10, 2023

But scaffolding already attempts to Detect triggers AFAIK.

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

@lsiepel
Copy link
Author

lsiepel commented Feb 14, 2023

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.

@ajcvickers
Copy link
Member

@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);
}

@ajcvickers
Copy link
Member

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.

@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants