I am using the following code to update my user table. The problem is that updated
it returns 0 when the data used is the same with the data in database and 1 otherwise.
var query = @"UPDATE users SET
firstname = @firstname,
lastname = @lastname
WHERE id = @userId";
var updated = await con.ExecuteAsync(query,
new
{
firstname = user.firstname,
lastname = user.lastname,
userId = user.id
});
return updated > 0;
For example:
1st try: firstname = "John", lastname = "Doe", userId = 1
Result = 1
2nd try: firstname = "John", lastname = "Doe", userId = 1
Result = 0
3rd try: firstname = "Johny", lastname = "Doe", userId = 1
Result = 1
Is this the expected behaviour?
Dapper doesn't supply this result, it only delivers what your DBMS finds fit to deliver. Apparently your DBMS returns the number of changed rows, not counting those that already matched the change. Different DBMS's implement different solutions to get more information on the updates made. You will need to look up the documentation for your particular DBMS to know how to get this.