Jacob Foshee
Jacob Foshee

Reputation: 2773

Example of OrmLite UpdateOnly with Multiple Fields

Is it possible to use the OrmLite extension method UpdateOnly to update multiple fields at once?

The example given in the documentation is:

db.UpdateOnly(new Person { FirstName = "JJ" }, p => p.FirstName);

Can I provide an expression with multiple fields in it? If so, what's the best operator to use given that the fields may be different data types.

Upvotes: 5

Views: 2597

Answers (1)

Jacob Foshee
Jacob Foshee

Reputation: 2773

An example was give in the following question: ServiceStack Ormlite and RowVersion support

A valid expression to use is an anonymous type; even one with implicit member names as described in this question: C#: Anonymous types and property names.

db.UpdateOnly(new Person { FirstName = "JJ", Age = 12 }, 
    (Person p) => new { p.FirstName, p.Age } );

Note that in my example I declared the type of the lambda argument. This may not be strictly necessary, but I was getting a Mono compiler error without it.

Error CS0016: Could not write to file `***', cause: Type '<>__AnonType1`2' was not completed.

Upvotes: 6

Related Questions