I'm trying to enhance my repository so it is the one responsible for ordering. I've applied the answer from this question and as far as the repository is concerned, I'm pretty sure it done.
The problem I'm running into is that I'm not sure how to now pass an array to the methods in the repository. The compiler keeps yelling at me about delegates. In the linked question above, the author is essentially doing what I want so it must be possible.
Here's my repository code:
public virtual IList<TEntity> SelectOrderedList(
Expression<Func<TEntity, bool>>[] Orderers,
bool Ascending = true) {
IOrderedQueryable<TEntity> TemporaryQueryable = null;
foreach (Expression<Func<TEntity, bool>> Orderer in Orderers) {
if (TemporaryQueryable == null) {
TemporaryQueryable = (Ascending ? this.ObjectSet.OrderBy(Orderer) : this.ObjectSet.OrderByDescending(Orderer));
} else {
TemporaryQueryable = (Ascending ? TemporaryQueryable.ThenBy(Orderer) : TemporaryQueryable.ThenByDescending(Orderer));
};
};
return TemporaryQueryable.ToList();
}
On a side note, I'm not 100% sure that I'm supposed to use Expression<Func<TEntity, bool>>
. For some reason I have a feeling that it's supposed to be Expression<Func<TEntity, int>>
, but I'm not too sure.
Anyway, I would really appreciate it if someone can show me how to actually call that. Bonus points and love if you can make it work like a params
argument.
SelectOrderedList(o1 => (o1.Something), o2 => (o2.SomethingElse))
. So I want to pass in multiple expressions to the method so they can perform OrderBy/ThenBy... – Inadmissible