Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
舉個簡單的例子,讓我們嘗試使用實體框架實際上不知道它的類型從數據庫中獲取的對象:
private DbContext db;
private dynamic test(dynamic entity)
{
return db.Set(entity.GetType()).First(x => x.Id == entity.Id);
}
我該如何做這項工作?
你可以試試http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx –