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"?
Asked
Active
Viewed 350 times
1
-
Something like this? [Dynamic LINQ OrderBy on `IEnumerable
`](https://stackoverflow.com/questions/41244/dynamic-linq-orderby-on-ienumerablet/233505#233505) – Marc Gravell Dec 01 '17 at 11:42 -
1Could you give an example of what you have already? – Filip Cordas Dec 01 '17 at 13:16
1 Answers
2
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
- 678
- 2
- 7
- 14