123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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<TEntity> : IGridResultSet<TEntity>
- {
- 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<TEntity> _rows;
- public List<TEntity> rows {
- get
- {
- return _rows;
- }
- set
- {
- _orderby = (OrderByStatementView)HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"];
- if (_orderby != null)
- {
- value.Sort(new Comparison<TEntity>(listComparision));
- HttpContext.Current.Session["Bowin_Common_Linq_Entity_CurOrderby"] = null;
- }
- _rows = value;
- }
- }
- public int total { get; set; }
- }
- }
|