I want to define some lambda expression that represent updates of properties of instances of a class.
I try to write that as below:
Expression<Action<User>> update = user => user.Name = "Joe Foo";
But I have a compilation error:
Error CS0832 An expression tree may not contain an assignment operator.
How to represent this update with a lambda.
EDIT
My goal is for a business service to send updates to a generic repository. This repository could analyze the expression of the lambdas to build query to send to the database engine.
An example of a business service could be:
public void DoStuff(String userId, ...)
{
// Business logic here
// ...
// Persist updates determined above
this.repository.Update(
// First parameter is the filter of entities to updates
x => x.Id == userId,
// Next parameters are updates to apply
x => x.FirstName = "John",
x => x.LastName = "Foo",
...);
}