Dapper, 批量插入,批量更新, 以及in, like
1. 批量插入
public async Task CreateBusinessItemAsync(IEnumerable<BusinessItemsEntity> businessItemsEntities)
{
var bizid = businessItemsEntities.First().BizId;
await _connection.DbConnection.ExecuteAsync("delete from BusinessItems where bizid=@BizId;", new { bizId= bizid });
string sql = @"INSERT INTO BusinessItems
([BizId]
,[ExpiredTime]
,[DisposeTime]
,[Remark]
,[ProductCategoryCode],Status)
values
(@BizId
,@ExpiredTime
,@DisposeTime,@Remark, @ProductCategoryCode,@Status);";
await _connection.DbConnection.ExecuteAsync(sql, businessItemsEntities);对, 就是这么暴躁, 直接把列表传进去就完事了
2. 批量更新.
参考 http://www.cnblogs.com/wuyunblog/p/9456756.html
1. where in 批量更新, 这时候所有需要更新的值都是一个同样的值
2. 如果每条语句更新的值都不一样呢
3. 模糊查询
方法1 https://stackoverflow.com/questions/6030099/does-dapper-support-the-like-operator
db.Query<Remitente>("SELECT * FROM Remitentes WHERE Nombre LIKE @n", new { n = "%" + nombre + "%" }) .ToList();
方法2