实体框架代码首先插入方法钩子

编程入门 行业动态 更新时间:2024-10-26 22:28:07
本文介绍了实体框架代码首先插入方法钩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

更多推荐

实体框架代码首先插入方法钩子

本文发布于:2023-10-25 03:17:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1525762.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:钩子   实体   框架   代码   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!