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 @ 2021-01-26 10:27  Nine4酷  阅读(74)  评论(0)    收藏  举报