using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using System.Reflection; using System.Linq.Expressions; namespace Bowin.Common.Linq.Entity { [Serializable] public class GridResultSet : IGridResultSet { private OrderByStatementView _orderby; private int listComparision(TEntity source, TEntity target) { var entityType = typeof(TEntity); var propertyInfo = entityType.GetProperty(_orderby.OrderBy); if (propertyInfo == null) { throw new Exception("类" + entityType.Name + "不包含" + _orderby.OrderBy + "属性。"); } var sourceValue = propertyInfo.GetValue(source, null); var targetValue = propertyInfo.GetValue(target, null); if (_orderby.isAsc) { return Convert.ToString(sourceValue).CompareTo(Convert.ToString(targetValue)); } else { return Convert.ToString(targetValue).CompareTo(Convert.ToString(sourceValue)); } } private List _rows; public List rows { get { return _rows; } set { _orderby = (OrderByStatementView)HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"]; if (_orderby != null) { value.Sort(new Comparison(listComparision)); HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"] = null; } _rows = value; } } public int total { get; set; } } }