ServiceStack/Issues

IDbConnection.UpdateOnly does not work with request.ConvertTo()

Closed this issue · 1 comments

Occurs in ServiceStack v5.13.1

db.UpdateOnly(() => request.ConvertTo<Setting>());

Error occurs in void PrepareUpdateRowStatement<T>(IDbCommand dbCmd, Dictionary<string, object> args, string sqlFilter) (Object reference not set to a reference of an object)

Expected behavior is an update on all rows of the table.

mythz commented

UpdateOnly method requires a Constructor Expression which is what OrmLite scans to determine which properties to update, e.g:

db.UpdateOnly(() => new Setting { Id = ... }));

To update an instance you need to use what's been renamed to UpdateOnlyFields in v5.13+:

db.UpdateOnlyFields(request.ConvertTo<Setting>(), onlyFields: p => new { p.Name, p.Age });