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

1

5

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);
Flaunt answered 17/5, 2017 at 17:20 Comment(0)
H
8

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 });
Haller answered 17/5, 2017 at 23:51 Comment(1)
That did it. ThanksFlaunt

© 2022 - 2024 — McMap. All rights reserved.