Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Code First On Insert method hooks

I'm trying to attach an audit log to an entity I've written, I'm wondering if there are hooks into a context that I can override to provide the desired functionality.

What I'm looking to do is:

  • On Insert run method A
  • On Update run method B
  • On Delete run method C

I could manually add this in a controller but I'd rather a more concrete solution, the desired effect is that no method can insert into the table without also inserting into the audit log.

like image 791
Valchris Avatar asked Oct 04 '11 21:10

Valchris


1 Answers

This project shows how you can add pre- and post-action hooks into an Entity Framework 4.1 DbContext. You can either extend its HooksDbContext class or see how it implements the hooks in the code and change it to suit your purposes.

like image 136
StriplingWarrior Avatar answered Oct 21 '22 01:10

StriplingWarrior