【发布时间】:2018-05-15 12:18:34
【问题描述】:
是否可以在 C# 中使用反射来 OrderBy IQueryable 以获取属性名称以按属性属性进行排序,例如 Attribute Name = "Key"?
【问题讨论】:
-
你能举一个你已经拥有的例子吗?
标签: c# generics reflection attributes iqueryable
是否可以在 C# 中使用反射来 OrderBy IQueryable 以获取属性名称以按属性属性进行排序,例如 Attribute Name = "Key"?
【问题讨论】:
标签: c# generics reflection attributes iqueryable
已解决: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();
【讨论】: