Inserts using Dapper.NET

dapper

Question

I am using Dapper.NET for my database connections.

So far, I have resorted to hand writing all the SQL I need for Inserts and Updates, I've found this old post from Sam Saffron
Performing Inserts and Updates with Dapper

However, it doesn't lead to anything conclusive with regards to how to do inserts and updates from POCO objects, other than a few links to code that are several years old by now.

Since then, has a new small helper library to autogenerate what is needed popped up?

Accepted Answer

You can use Dapper.Contrib

//Insert one entity
connection.Insert(new Car { Name = "Volvo" });

//Insert a list of entities
connection.Insert(cars);

//Update one entity
connection.Update(new Car() { Id = 1, Name = "Saab" });

//Update a list of entities
connection.Update(cars);

See more examples here.



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why