asp.net mvc equivalent of rails callback before_save

喜你入骨 提交于 2020-01-04 13:35:29

问题


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

In rails there is before_save.

Thanks


回答1:


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)
{
}


来源:https://stackoverflow.com/questions/2817456/asp-net-mvc-equivalent-of-rails-callback-before-save

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!