0
嗨我想要使用該代碼來獲取包含用戶的客戶的屬性User.Email。但它的一個對象(用戶類型用戶),所以它引發異常。我應該修補什麼?獲取內部對象的屬性
public static IQueryable<T> OrderByField<T>(this IQueryable<T> q, string SortField, bool Ascending)
{
if (!string.IsNullOrWhiteSpace(SortField))
{
var param = Expression.Parameter(typeof (T), "p");
var prop = Expression.Property(param, SortField);
var exp = Expression.Lambda(prop, param);
string method = Ascending ? "OrderBy" : "OrderByDescending";
Type[] types = new Type[] {q.ElementType, exp.Body.Type};
var mce = Expression.Call(typeof (Queryable), method, types, q.Expression, exp);
return q.Provider.CreateQuery<T>(mce);
}
else
{
return q;
}
}