I want to be able to refresh an object by finding it's match in list of objects that I've got back from the database. I can do it with reflection - but am sure there must be a way of getting the Property Selector within a Where clause.
This is the kind of thing I want to call ...
MyObject = GetRefreshedObject(MyObject, RefreshedObjects, () => ID);
But I'm a bit stuck with the Method!
public static TE GetRefreshed<TE, P>(TE entity, IEnumerable<TE> refreshed, Expression<Func<TE, P>> selector) where TE : class
{
if (entity == null) return null;
return refreshed.Where(x => x.[Selector == entity.Selector]).FirstOfDefault();
//The square bracket bits obviously don't work but hopefully show what I'm trying to achieve!
}