Add/Insert style of petapoco vs dapper
Asked Answered
C

3

5

I am delighted by this:

// Insert a record with peta poco

var a = new Article();
a.title="My new article";
a.content="PetaPoco was here";
a.date_created=DateTime.UtcNow;
db.Insert(a);

I am distracted by this:

// Insert a record with dapper

var a = new Article();
a.title="My new article";
a.content="PetaPoco was here";
a.date_created=DateTime.UtcNow;
string articleQuery= "INSERT INTO Article VALUES (@Title, @Content, @Date)";        
connection.Execute(articleQuery, new { Title = a.Title, Content = a.Content, Date = a.Date });

I am new to dapper and peta poco. It might be that there is more in dapper that I have not found but I really do not like the way I have to do an insert. Peta poco seems to do it very ormish.

Can dapper do this somehow too?

Cervicitis answered 22/10, 2013 at 18:26 Comment(0)
M
7

Check out dapper extensions for 'magic' CRUD operations with Dapper:

using (SqlConnection cn = new SqlConnection(_connectionString))
{
    cn.Open();
    Person person = new Person { FirstName = "Foo", LastName = "Bar" };
    int id = cn.Insert(person);
    cn.Close();
}

Also see this thread for more...

Mountaintop answered 22/10, 2013 at 21:43 Comment(0)
S
13

If you like the PetaPoco style the better, just go for it. Although Dapper is more famous, PetaPoco has the same performance, has the same concepts but it's a bit more flexible (IMO)

Sawtoothed answered 23/10, 2013 at 14:6 Comment(2)
@Gaspa79 yes, you are right. Roughly enough for the vast majority of apps.Sawtoothed
For MS Access/Jet database, PetaPoco is your saving grace.Usanis
M
7

Check out dapper extensions for 'magic' CRUD operations with Dapper:

using (SqlConnection cn = new SqlConnection(_connectionString))
{
    cn.Open();
    Person person = new Person { FirstName = "Foo", LastName = "Bar" };
    int id = cn.Insert(person);
    cn.Close();
}

Also see this thread for more...

Mountaintop answered 22/10, 2013 at 21:43 Comment(0)
O
-1

Developers use Drapper because of its performance. For many websites PetaPoco is good enough but if you want to extract all the server 'juice' use Drapper. In fact it is the ORM used by Stackoverflow. You can see all ORM performance comparison here

Oraliaoralie answered 26/3, 2015 at 13:0 Comment(1)
dude performance of Dapper and PetaPoco is basically identical 49ms v 52ms (v 631 for EF in the example).Epeirogeny

© 2022 - 2024 — McMap. All rights reserved.