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 –