Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

orm

lambda

npoco

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);
like image 261
Tony Avatar asked May 17 '17 17:05

Tony


1 Answers

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 });
like image 63
NetMage Avatar answered Oct 15 '22 04:10

NetMage