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
No, you cannot use dynamic in a Linq to Entities query. But you can build the Lambda Expression at runtime.
public virtual Expression> UpdateCriterion()
{
var param = Expression.Parameter(typeof(TSubclass));
var body = Expression.Convert(Expression.Property(param, "ID"), typeof(object));
return Expression.Lambda>(body, param);
}
If the TSubclass type does not have an ID property Expression.Property(param, "ID") will throw an exception.
Additionally you could use the MetadataWorkspace from your entity model to get the Primary Key column for TSubclass.