5

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.

Jacob Foshee
  • 2,704
  • 2
  • 29
  • 48

1 Answers1

6

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.
Community
  • 1
  • 1
Jacob Foshee
  • 2,704
  • 2
  • 29
  • 48