I’m trying to generate an UPDATE command based on Expression trees (for a batch update).
Assuming the following UPDATE command:
UPDATE Product
SET ProductTypeId = 123,
ProcessAttempts = ProcessAttempts + 1
For an expression like this:
Expression<Func<Product, Product>> updateExpression = entity =>
new Product() {
ProductTypeId = 123,
ProcessAttempts = entity.ProcessAttempts + 1
};
How can I generate the SET part of the command?
SET ProductTypeId = 123,
ProcessAttempts = ProcessAttempts + 1
This is a very simplistic approach, but I hope it’s good enough: