views:

53

answers:

1

After using .NET for several years, I've spent the last few months in the far off land of Ruby on Rails. While I can clearly see where much of Microsoft's MVC framework got it's influence, one of the things that I find myself suddenly missing when development in .NET are the Rails Model callbacks.

Specifically, you can add a callback to before_save, after_save, before_create, after_create, etc. and then specify a function to be called at those points in execution (which seems very similar to aspect oriented programming).

My question is, out of the box, does .NET 3.5/ASP.NET MVC offer anything similar to the callbacks in Rails? For example, if I have an inserted_datetime and updated_datetime column on one of my database tables, instead of making sure those columns get updated in the controller, I'd like to be able to tell my model that every time the "Group" object gets saved to the database, update the updated_datetime column.

Is this possible? Does this question even make sense?

+1  A: 

Out of the box LINQ to SQL does a bit of that. It calls a OnMYFIELDChanging and OnMYFIELDChanged events.

Not as feature rich as you are now used to but i think you can extend this yourself.

Not even sure I got this answer right to be honest.

griegs
+1 I agree. All L2S entity objects are partial and you can extend them easily with events that will give you a more granular way of managing entity changes.
Sergey
Thanks for that. Kinda figured as much but never actually had to do it.
griegs
Accepting the answer, since I think this really is the best way. Unfortunately, I'd rather have *less* granularity. :) Using the default configuration, if I want to catch any changes, I have to remember to write more code every time I add a new field.
jerhinesmith