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);
        }
    }

  

posted @ 2019-08-11 13:07  狂乱贵公子  阅读(552)  评论(0编辑  收藏  举报