ServiceStack / Issues

Issue Tracker for the commercial versions of ServiceStack
11 stars 8 forks source link

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

Closed labilbe closed 2 years ago

labilbe commented 2 years ago

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 2 years ago

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 });