PetaPoco
PetaPoco copied to clipboard
Hook into Insert/Update on specific POCOs
I'm just in the planning stages on a project and a requirement is to save a copy (in an almost duplicate table) of any changes to specific records.
I was thinking that I may hook into the Insert/Update methods to also save the same data into another POCO. Looking at the code I'm not sure what the best approach is for raising and event / subscribing to an observable / etc...
I thought I would ask here in case anyone has already done this using PetaPOCO. (Doesn't look like the OnExecutedCommand event is suitable for this purpose unfortunately)
Thanks, Paul
@picasso566 Maybe you could create a wrapper for PetaPoco and intercept any method call you like?
Hmm 🤔
What are your thoughts on making
private object ExecuteInsert(string tableName, string primaryKeyName, bool autoIncrement, object poco)
private int ExecuteUpdate(string tableName, string primaryKeyName, object poco, object primaryKeyValue, IEnumerable<string> columns)
protected virtual?
protected virtual object ExecuteInsert(string tableName, string primaryKeyName, bool autoIncrement, object poco)
protected virtual int ExecuteUpdate(string tableName, string primaryKeyName, object poco, object primaryKeyValue, IEnumerable<string> columns)
This way you could use extend the PetaPoco.Database class and intercept those methods to achieve the insert/update hook.
I can't see any issue with this, and I'm sure it'll be of use to others. If you agree, can you submit a PR and I'll merge it
Thank you for your help on this. I will certainly consider it.
I was thinking I might use it for logging purposes and there might be as better was to go on the sql side. But this may also work.
Paul
On May 4, 2017 09:17, "Wade Baglin" [email protected] wrote:
Hmm 🤔
What are your thoughts on making
private object ExecuteInsert(string tableName, string primaryKeyName, bool autoIncrement, object poco)
private int ExecuteUpdate(string tableName, string primaryKeyName,
object poco, object primaryKeyValue, IEnumerable
protected virtual?
protected virtual object ExecuteInsert(string tableName, string primaryKeyName, bool autoIncrement, object poco)
protected virtual int ExecuteUpdate(string tableName, string
primaryKeyName, object poco, object primaryKeyValue,
IEnumerable
This way you could use extend the PetaPoco.Database class and intercept those methods to achieve the insert/update hook.
I can't see any issue with this, and I'm sure it'll be of use to others. If you agree, can you submit a PR and I'll merge it
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/CollaboratingPlatypus/PetaPoco/issues/380#issuecomment-299070524, or mute the thread https://github.com/notifications/unsubscribe-auth/AAYEgOrHTOECX8sH6eMr8eIsFzgGAms-ks5r2RkogaJpZM4MqK8Q .
While doing this can you make "private AddParam" protected, too. UseCase: If deriving from Database you can implement new execute functionsand use the AddParam function for robust parameter insertion.
Sounds good