Sql-server – how to scaffold the database triggers

csql server

I'm trying to find a way to include table triggers when reverse-engineering the database. but I can't seem to find a way to do it.

I'm using SQLserver and .netCore 3.1 with efcore.

and each time I scaffold the dbcontext , the triggers aren't scaffolded.

Here's my command

dotnet ef dbcontext scaffold "server={server};database={database};user={user};password={password}" Microsoft.EntityFrameworkCore.SqlServer --project  "{project}" --output-dir "Models" --force

Best Answer

It's not possible to scaffold Triggers, and it doesn't make much sense since they are a database specific type of object (not sure what they could map to in C#?). They don't directly describe the database model, as opposed to Tables, Columns, and Keys. What is your end goal that you wanted to scaffold the Triggers?

Please see Entity Framework Core - Reverse Engineering documentation for more information.

Particularly the How it works section details what is scaffolded from the database:

Reverse engineering starts by reading the database schema. It reads information about tables, columns, constraints, and indexes.

Next, it uses the schema information to create an EF Core model. Tables are used to create entity types; columns are used to create properties; and foreign keys are used to create relationships.

Finally, the model is used to generate code. The corresponding entity type classes, Fluent API, and data annotations are scaffolded in order to re-create the same model from your app.