Skip to content

Performing Operations during Poco events (Insert, Update, etc)

Sam Critchley edited this page Aug 6, 2015 · 1 revision

To do things when an entity is inserted, updated, deleted etc. you can write your own class inheriting from Database. You can then override methods like OnInsert, OnUpdate.

Example:

public class CustomDatabase : Database
    {
        protected override bool OnUpdating(UpdateContext updateContext)
        {
            var entity = updateContext.Poco as CommonEntity;
            if (entity != null)
            {
                entity.DateModified = DateTime.UtcNow;
            }
            return base.OnUpdating(updateContext);
        }
    }