开发者

asp.net mvc equivalent of rails callback before_save

开发者 https://www.devze.com 2022-12-30 04:20 出处:网络
Hi i\'m looking for a asp.net mvc开发者_如何学C callback for elaborate data before save a model.

Hi i'm looking for a asp.net mvc开发者_如何学C 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)
{
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号