Search code examples
c#lambdaormnpoco

NPoco: Update some (but not all) columns using Expression notation


Using NPoco, I'm trying to figure out how to update more than one column of an object (but not all of them). This works...

db.Update(item, new[] { "status", "tracking_number", "updated_at" });

...but I'm trying to use the notation below so I can use my object's property names rather than the database column names.

int Update<T>(T poco, Expression<Func<T, object>> fields);

How do I list more than one column using the above syntax? This will update a single column but I assume I can list more than one but I can't figure out the notation.

db.Update(item, i => i.Status);

Solution

  • Looking through the code, it seems you use an anonymous object:

    x => x.SomeProperty1 or x => new{ x.SomeProperty1, x.SomeProperty2}
    

    so in your example:

    db.Update(item, i => new { i.Status, i.TrackingNumber, i.UpdatedAt });