Generate dynamic UPDATE command from Expression<Func<T, T>>
- by Rui Jarimba
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