Alex Rivera | Logout

PetaPoco Insert - Fastest Method?

Asked 2011-12-31T19:00:34.857
9

What is the fastest option for inserting records into the database: using which of these:

  • Database.Insert(poco)
  • Database.Insert(tableName, pkName, poco)
  • Database.Save(poco)
  • Database.Save(tableName, pkName, poco)

Which one should I use for performance reasons? One is not less convenient to me than the other...

Thanks.

Edit
Report

1 Answer

3

In all 4 of the methods you listed, for inserts, it looks like PetaPoco always calls the following method of the Database class:

public object Insert(string tableName, string primaryKeyName, bool autoIncrement, object poco)

And the Database.Insert(tableName, pkName, poco) does the least amount of work (it is basically just a pass through method), so I would assume it is the one with the best performance.

Here is the code for Insert(string, string, object):

public object Insert(string tableName, string primaryKeyName, object poco)
{
    return Insert(tableName, primaryKeyName, true, poco);
}

It would probably be slightly (and unnoticeably) faster to just call the Insert(string, string, bool, object) overload directly.

answered 2011-12-31T22:08:08.443

Your Answer