public IQueryable<TEntity> QueryJoin(Expression<Func<TEntity, bool>> where, string[] tablesName)
{
if (tablesName == null || tablesName.Any() == false)
{
throw new Exception("连表查询最少也要一个表,所有QueryJoin方法中tablesName中最少也需要有一个表名");
}
DbQuery<TEntity> query = this._dbset;
foreach (string tableName in tablesName)
{
//不断的连表,直到把tablesName里的所有表都连完
query = query.Include(tableName);
}
return query.Where(where); //然后对连表进行条件筛选查询
}
/// <summary>
/// 带条件的分页查询
/// </summary>
/// <typeparam name="TKey">按哪个字段进行排序</typeparam>
/// <param name="pageindex">当前页</param>
/// <param name="pagesize">页大小</param>
/// <param name="rowCount">数据总条数</param>
/// <param name="order">排序</param>
/// <param name="where">筛选条件</param>
/// <returns></returns>
public IQueryable<TEntity> QueryByPage<TKey>(int pageindex, int pagesize, out int rowCount, Expression<Func<TEntity, TKey>> order, Expression<Func<TEntity, bool>> where)