i fix it check this
/// <summary>
///
/// </summary>
/// <param name="whereData"></param>
/// <param name="orderBy">
/// how To Use :
/// GetData(where, orderBy: q => q.OrderByDescending(d => d.Date), null)
/// </param>
/// <param name="includes">
/// how To Use :
/// new List<string> { "SerialList", "CategoryItem" }
/// </param>
/// <param name="leftJoinSelection">
/// زمانی که ارتباط یک به یک داریم و نیاز داریم ایتم هایی با
/// حتما با OR از هم جدا بشه
/// how To Use :
/// You Must Use Or on Many Left Join Parameter , Not Use And!
/// x=>x.CategoryID==0 | x.PersonID == 0
/// </param>
/// <returns></returns>IEnumerable<TSource> source, Func<TSource, TKey>
public virtual IEnumerable<TEntity> GetData(Expression<Func<TEntity, bool>> whereData = null
, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
List<string> includes = null, Expression<System.Func<TEntity, bool>> leftJoinSelection = null)
//List<Expression<Func<TEntity, IProperty>>>
// , List<string> includes = null
{
IQueryable<TEntity> query = _dbset;
IQueryable<TEntity> leftData = _dbset;
if (whereData != null)
{
query = query.Where(whereData);
}
if (includes != null)
{
foreach (var includesItem in includes)
{
query = query.Include(includesItem);
}
}
if (leftJoinSelection != null)//we use left join mode
{
if (whereData != null)
{
leftData = leftData.Where(ArmanHelper.Helper.And(whereData, leftJoinSelection));
}
else
{
leftData = leftData.Where(leftJoinSelection);
}
}
else //لفت جوین نداره پس مرتب سازی فراموش نشه
{//dont use left join mode then normal orderBy
if (orderBy != null)
{
query = orderBy(query);
}
}
List<TEntity> returnData = new List<TEntity>();
if (leftJoinSelection != null)//we use left join mode
{
returnData = query.ToList();
returnData.AddRange(leftData.ToList());
if (orderBy != null)
{
if (orderBy != null)
{
returnData = orderBy(returnData.AsQueryable()).ToList();
}
}
}
else // افت جوین نداریم و روال عادی داده ها لیست میشه و برمیگرده
{//dont use Left join Mode then return normal method
return query.ToList();
}
return returnData.ToList();
}
how to use:
_genericRepositoryTrade = new GenericRepository<Commodity>(_eFContextA);
_genericRepositoryPerson = new GenericRepository<CommoditySerial>(_eFContextA);
_genericRepositoryCategory = new GenericRepository<Category>(_eFContextA);
var trades1 = _genericRepositoryTrade.GetData(x => x.ID < 1000, orderBy: q => q.OrderByDescending(d => d.ID)
, new List<string> { "SerialList", "CategoryItem" },
x=>x.CategoryID==0 );