maxtoroq / DbExtensions

Data-access framework with a strong focus on query composition, granularity and code aesthetics.
https://maxtoroq.github.io/DbExtensions/
Apache License 2.0
227 stars 41 forks source link

Support updates when using updatable keys #56

Closed maxtoroq closed 6 years ago

maxtoroq commented 7 years ago

SqlTable uses the new key in the update predicate instead of the old key. Since there's no change tracking, a new overload is required.

A workaround that I'd recommend only for single column keys is the following:

SqlBuilder updateSql = db.Table<Entity>()
   .CommandBuilder
   .BuildUpdateStatementForEntity(entity);

updateSql.ParameterValues[updateSql.ParameterValues.Count - 1] = oldId;

db.Execute(updateSql, affect: 1, exact: true);
maxtoroq commented 6 years ago

Shipped in v6.1.0

Added new SqlTable.Update overload, e.g.:

db.Table<Entity>.Update(entity, oldId);