使用 Dapper.NET 插入

Inserts using Dapper.NET

我正在使用 Dapper.NET 进行数据库连接。

到目前为止,我已经手写了插入和更新所需的所有 SQL,我从 Sam Saffron 找到了这个旧的 post
Performing Inserts and Updates with Dapper

但是,关于如何从 POCO 对象进行插入和更新,它并没有得出任何结论,除了几个指向现在已有几年历史的代码的链接。

从那以后,有一个新的小助手库来自动生成需要的东西吗?

您可以使用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);

查看更多示例here