EF 动态IQueryable

    public static class DbContextExtension
    {
        public static IQueryable Query(this DbContext context, Type entityType)
        {
            var SetMethod = typeof(DbContext).GetMethod(nameof(DbContext.Set));
            return (IQueryable)SetMethod.MakeGenericMethod(entityType).Invoke(context, null);
        }
    }

  

原文地址:https://www.cnblogs.com/saving/p/11334677.html