vendredi 23 juin 2017

Sorting by Reflection using GetProperty

I have a generic class with a method that needs to sort a generic entity.

However, an error occurs saying that it does not recognize the Reflection GetProperty method, since lambda can not translate.

How can I do this sort ordering logic?

public IEnumerable<TEntity> GetAll()
{
    var obj = _repository.GetAll()
        .OrderByDescending(x => x.GetType().GetProperty(typeof(TEntity).Name + "Id"));

    return obj.Pagination();
}

Here is the error image:

enter image description here





Aucun commentaire:

Enregistrer un commentaire