如何在 SubSonic ORM 上插入 ActiveRecord 上的保存方法? [英] How to intersept the save method on ActiveRecord on SubSonic ORM?

查看:16
本文介绍了如何在 SubSonic ORM 上插入 ActiveRecord 上的保存方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要拦截 Save 方法,做一些验证,改变一些属性,然后让它再次正常运行.

I need to intercept the Save method, do some validations, alter some properties and then let it go again normally.

我该怎么做?

谢谢!亚历克斯

推荐答案

我建议添加以下部分方法,以便在实际操作之前触发:

I would recommend adding the following partial methods to be fired before their actual action:

OnSave(CancelEventArgs e); 
OnAdd(CancelEventArgs e); 
OnUpdate(CancelEventArgs e); 
OnDelete(CancelEventArgs e);

这不是一个事件,但无论如何我都会使用 CancelEventArgs,它很友好,人们知道它并知道如何使用它,并且使用它可以从部分方法中取消实际操作.

This isn't an event but I would use CancelEventArgs anyway, it's friendly, people know it and know how to use it and with it the actual action can be canceled from the partial methods.

这两个也应该添加到在实际操作后触发的现有列表中:

These two should be added too to the list of the existing ones that fire after their actual action:

OnAdded(); 
OnUpdated();

我不喜欢 OnAdded() 名称,但如果采用 Add 而不是 Insert 那么我们必须坚持使用它.

I don't like that OnAdded() name but if Add was adopted instead of Insert then we must stick with it.

就是这样......通过这些部分,我认为我们涵盖了实际数据持久性方法的所有前后关系,使我们能够更灵活地为我们的数据做任何我们想做的事情.

And that's it... With these partials I think we cover all the befores and afters of the actual data persistence methods giving us a greater flexibility to do whatever we want we our data.

我可以实现这一点,但我总是害怕触及 tt 文件,因为未来的更新将清除我所有的自定义更改!:)

I can implement this but I'm always afraid of touching the tt files because future updates will wipe off all my custom changes! :)

谢谢!亚历克斯

这篇关于如何在 SubSonic ORM 上插入 ActiveRecord 上的保存方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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