I’m using EF 4.1 in POCO mode.
LINQ2SQL generates partial methods on the datacontext that get called when inserting/updated/deleting an entity. They’re helpful for cases like:
partial void InsertCampaign( Campaign instance )
{
instance.CreatedAtUTC = instance.ModifiedAtUTC = DateTime.UtcNow;
ExecuteDynamicInsert( instance );
}
partial void UpdateCampaign( Campaign instance )
{
instance.ModifiedAtUTC = DateTime.UtcNow;
ExecuteDynamicUpdate( instance );
}
So, my question is — with EF, how do you hook into the inserting/updating/deleting of entities so that you can perform operations such as the above? I would prefer not to have to do this manually every time I create/update an entity.
Thank you
Override SaveChanges() method in your DbContext and do something like: