Entity Framework 6 Code First Trigger

c# entity-framework entity-framework-6 sql

Question

In order to develop a Trigger, I would like to use Entity Framework 6 Code First.

What should I do?

I need the trigger because I'm building an application that will allow users to change the database directly, and I need to ensure that two columns in a table are not both null.

I've looked everywhere, but I can't find a method.

Is it possible to initially specify a trigger using code?

1
24
2/5/2016 8:50:22 PM

Accepted Answer

Although you can certainly manually run a statement that would establish a trigger, you would need to do this after the table was built because Entity Framework does not support triggers (if using migrations).

You can employ the method Ladislav described in EF 4.1 code-first table trigger addition.

Take notice of his caution, but bear in mind that EF won't be informed of any trigger adjustments. If your goal is to just make sure that two columns in a table are not null, a constraint would be more beneficial (constraints are also not supported by EF, but you can add them manually).

24
10/21/2017 2:26:01 PM

Popular Answer

Visit my library at zzz-5 zzz. Since it operates at the Entity Framework layer, changing the database directly will not cause the trigger events to fire. The URL is https://www.nuget.org/packages/EntityFramework.Triggers/ in NuGet.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow