1

Is it possible to in C# to OrderBy IQueryable with Reflection to get Property name for ordering by property attribute for example Attribute Name = "Key"?

Vaso Beruashvili
  • 478
  • 2
  • 4
  • 14

1 Answers1

0

Resolved with: System.Linq.Dynamic enter link description here

var keyPropertyName = typeof(TEntity).GetProperties()
    .First(p => p.CustomAttributes.Any(ca => ca.AttributeType.Name == "KeyAttribute")).Name;

return _dbSet.OrderBy(keyPropertyName).Skip(skip).Take(take).ToList();
Vaso Beruashvili
  • 478
  • 2
  • 4
  • 14