Whats an easy (less code) way to add business logic to a ‘code first’ model to execute before its saved to the database?
E.g. given the Albums model from the music store example
public class Album
{
public string Title { get; set; }
public Genre Genre { get; set; }
public DateTime LastUpdated { get; private set;}
}
e.g. if we add a LastUpdated property to the example, how can we ensure it’s automatically set if the entity is updated – perhaps on a save using someting like
private void album_OnSave()
{
this.LastUpdated = DateTime.Now;
}
1 Answer