【问题标题】:C# OrderBy IQueryable<T> with Reflection by Property with attribute named For example "Key"C# OrderBy IQueryable<T> 具有按属性反射的属性,例如“键”
【发布时间】:2018-05-15 12:18:34
【问题描述】:

是否可以在 C# 中使用反射来 OrderBy IQueryable 以获取属性名称以按属性属性进行排序,例如 Attribute Name = "Key"?

【问题讨论】:

标签: c# generics reflection attributes iqueryable


【解决方案1】:

已解决: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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-29
    • 1970-01-01
    • 2017-05-31
    • 2011-08-04
    • 2010-11-21
    • 1970-01-01
    • 1970-01-01
    • 2018-07-20
    相关资源
    最近更新 更多