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

  

Guess you like

Origin www.cnblogs.com/saving/p/11334677.html