实体框架代码首先插入方法钩子 [英] Entity Framework Code First On Insert method hooks

查看:121
本文介绍了实体框架代码首先插入方法钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试附加一个审计日志到我写的实体,我想知道是否有钩子到一个上下文,我可以覆盖以提供所需的功能。

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.

我想要做的是:


  • 插入运行方法A

  • 更新运行方法B
  • 删除运行方法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.

推荐答案

此项目显示了如何添加操作前和操作后钩入Entity Framework 4.1 DbContext。您可以扩展其 HooksDbContext 类,或者参见如何实现代码中的钩子,并根据您的目的进行更改。

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.

这篇关于实体框架代码首先插入方法钩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆