querybuilder
querybuilder copied to clipboard
Multiple/bulk update
Dapper can do bulk update. Following sample code is copied from StackOverFlow
_connection.Execute(@"update employees set Name = @Name where Id = @Id",
new List<Employee>
{
new Employee{Age = 1, Name = "foo", Id = 1},
new Employee{Age = 2, Name = "bar", Id = 2}
});
var result = _connection.Query<Employee>("select * from employees").ToList();
Assert.That(result.Count, Is.EqualTo(2));
Assert.That(result.FirstOrDefault(x => x.Id == 1).Name == "foo");
Assert.That(result.FirstOrDefault(x => x.Id == 2).Name == "bar");
It would be nice to have almost similar functionality as InsertMany
but also with more flexibility on WHERE
clause.
But for now, is there any alternative (nice) way to compile so I can pass the compiled query directly to Dapper? The challenge I have currently is, SqlKata is generating parameter names as @p0, @p1... @p2
while it is a little bit hard to determine which parameter is referring to which column.
Spending a few more hours, turns out I can get away with SqlResult.NamedBindings
🤭
Is this functionality available for use? I was looking for a way to update multiple rows based on a unique id for every row