I have the following Linq expression:
var itemToUpdate = ItemsUpdated.FirstOrDefault(x => x.Id == itemId);
I need to adapt it so that x.Id is a dynamically defined property, for example:
var itemToUpdate = ItemsUpdated.FirstOrDefault(x => x["Id"] == itemId);
I have tried the following already which I thought would be enough:
var itemToUpdate = ItemsUpdated.FirstOrDefault(x => (int)x.GetType().GetProperty("Id").GetValue(x) == itemId);
This runs without any errors, but any code after this statement does not execute therefore I assume something goes wrong with the expression above.