I have a question that I've yet to find an answer to after some research. Is there a way in Code First for Entity to create an Insert/Update/Delete Trigger? Currently I cannot find anything and the only thing eluding to it was suggestions of using code to do whatever work (insert/update/delete) after a method fires.
1 Answer
Entity Framework currently does not support creating triggers on the database itself, nor does there appear to be any in the near future (see what's being implemented for EF 6 here).
The only solution that you have is to do whatever it is you wanted to do after the Insert/Update/Delete finishes, preferably in your business logic (or, even better, in your repositories if you want to set it up like in this blog post).
2 Comments
IyaTaisho
That's what I feared. Seems like something they would want to invest in. I have a way around it though since I have a start up script when my project is first deployed. I could add the trigger then. Thanks.
Ibrahim Najjar
+1 on the answer, "preferably in your business logic" is the right way of doing things.