EntityTypeBuilder<T>.HasTrigger("My Trigger")

See original GitHub issue

Hi so we have to declare that our tables have triggers in EF 7 in order to get Inserts to work.

It seems this has to be done using the ModelBuilder as so…

 modelBuilder.Entity<Blog>()
        .ToTable(tb => tb.HasTrigger("SomeTrigger"));

I would have liked to do this inside the Configure method of my IEntityTypeConfiguration<T> classes however there’s no HasTrigger method available on EntityTypeBuilder<T>. Would it be possible to add this method?

Also if a table has multiple triggers do we have to declare each of these? If so how do you do this?

Issue Analytics

  • State:closed
  • Created 7 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
rojicommented, Feb 23, 2023

@micktion the HasTrigger method isn’t on EntityTypeBuilder, it’s on the TableBuilder that’s inside the ToTable method. So you can define a trigger as follows:

public void Configure(EntityTypeBuilder<Blog> builder)
{
    builder.ToTable(t => t.HasTrigger("SomeTrigger"));
}

Re multiple triggers… For now, HasTrigger doesn’t actually create the triggers - it’s simply a way to inform EF to use SQL that’s compatible with triggers (i.e. avoid the more efficient OUTPUT clause). So there’s no benefit in defining multiple triggers on the same table - just one should do the trick.

0reactions
micktioncommented, Feb 27, 2023

Guess I hadn’t…

protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
    configurationBuilder.Conventions.Add(_ => new BlankTriggerAddingConvention());
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity Framework 6 / SQL Server triggers - getting error
The error is actually telling you that you can't use an OUTPUT without an INTO clause, not "You cannot use triggers in Entity...
Read more >
Triggers for Entity Framework Core - On The Drift
Triggered by default supports recursion which means that changes to your DbContext from within your triggers will be recorded and subsequent triggers will...
Read more >
Add support for managing Triggers with EF migration #10770
So my question : Why ? Is there something difficult to manage with triggers ? Why could we add some custom operations on...
Read more >
Breaking changes in EF Core 7.0 (EF7)
This effectively calls HasTrigger on all your model's tables, instead of you having to do it manually for each and every table. SQLite...
Read more >
Entity Framework Community Standup - Triggers for EF Core
See how it is implemented and how the project uses EF Core's ChangeTracker and ... Entity Framework Community Standup - Triggers for EF...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found