asp.net mvc等同于rails回调before_save [英] asp.net mvc equivalent of rails callback before_save

查看:132
本文介绍了asp.net mvc等同于rails回调before_save的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在rails中有一个before_save。



谢谢

解决方案

如果您正在使用Entity Framework(您的标签表示)一个href =https://stackoverflow.com/questions/450601/intercept-entity-saving-with-ado-net-net-entities-framework>这个StackOverflow文章应该能够帮助你。基本上你可以拦截SavingChanges事件,并且做任何你想要的。将它放在一个部分类中,将以下方法添加到对象上下文中:

  partial void OnContextCreated()
{
SavingChanges + = DoWhatYouMust;
}

private void DoWhatYouMust(object sender,System.EventArgs e)
{
}


Hi i'm looking for a asp.net mvc callback for elaborate data before save a model.

In rails there is before_save.

Thanks

解决方案

If you are using Entity Framework (which your tag indicates), then this StackOverflow post should be able to help you out. Basically you can intercept the SavingChanges event, and do whatever you want. Put this in a partial class that adds the following methods to your object context:

partial void OnContextCreated()
{
    SavingChanges += DoWhatYouMust;
}

private void DoWhatYouMust(object sender, System.EventArgs e)
{
}

这篇关于asp.net mvc等同于rails回调before_save的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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