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酷  阅读(67)  评论(0编辑  收藏  举报