Petapoco doing something when Update is performed

82 views Asked by At

I have to perform some operation whenever the Upload() Petapoco method is called... The response could be to override it inheriting the Database class but unfortunately Upload() is private... Is there anybody with the same problem?

1

There are 1 answers

0
Eduardo Molteni On

Short answer: Fork PetaPoco (it's open source) and change the method to do what you want.

Suggested alternative solution: Use an extension method that execute the Update, and then do what you want.

    // Example
    public static void SaveAndLog(this PetaPoco.Database db, object rec) {
        bool IsNew = db.IsNew(rec);
        db.Save(rec);
        db.Log(rec, (IsNew ? "Creó" : "Editó"));
    }

Why? Because it's better to use the original package and get all the updates without worring about merges, and also, you have the freedom to use the original method when suited.