【问题标题】:Inserts using Dapper.NET使用 Dapper.NET 插入
【发布时间】:2015-11-02 09:54:37
【问题描述】:

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

到目前为止,我已经求助于手写插入和更新所需的所有 SQL,我找到了 Sam Saffron 的这篇旧帖子
Performing Inserts and Updates with Dapper

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

从那时起,是否弹出了一个新的小型帮助库来自动生成需要的内容?

【问题讨论】:

标签: dapper


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-13
    • 1970-01-01
    • 2015-05-05
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    • 2012-05-08
    • 2014-08-30
    相关资源
    最近更新 更多