First, spec. We use MVC5, .NET 4.5.1, and Entity framework 6.1.
In our MVC5 business application we have a lot of repetitive CRUD code. My job is to \"automate\" mos
Take a look at this answer. It uses reflection to get the ID Property. I think it solves your problem:
public static object GetPropValue(object src, string propName)
{
return src.GetType().GetProperty(propName).GetValue(src, null);
}
Then you replace your lambda expression by
return entity => GetPropValue(entity, "ID");
I've not tested, since I have no code fully working to test it. If it works please let us know.