Linq Distinct 指定属性过滤

        //省份
            this.RepAddressList.DataSource = mlist.Distinct(new FastPropertyComparer<A_pro_platform>("Province")).ToList();
            this.RepAddressList.DataBind();
            //首字母
            this.RepInitialList.DataSource = mlist.Distinct(new FastPropertyComparer<A_pro_platform>("PlatformNameFirstInitial")).ToList();
            this.RepInitialList.DataBind();
            //时间
            this.RepDtList.DataSource = mlist.Distinct(new FastPropertyComparer<A_pro_platform>("GetOnlineTimeYear")).ToList();
            this.RepDtList.DataBind();

public class A_pro_platform
    {
        #region 基本属性
        /// <summary>
        /// 平台编号
        /// </summary>
        public Guid PlatformID { get; set; }
        /// <summary>
        /// 平台名称
        /// </summary>
        public string PlatformName { get; set; }
        /// <summary>
        /// 平台名称首字母
        /// </summary>
        public string PlatformNameInitial { get; set; }
        /// <summary>
        /// 公司名称
        /// </summary>
        public string Company { get; set; }
        /// <summary>
        /// 网站
        /// </summary>
        public string Website { get; set; }
        /// <summary>
        /// 省份
        /// </summary>
        public string Province { get; set; }
        /// <summary>
        /// 城市
        /// </summary>
        public int City { get; set; }
        /// <summary>
        /// 平台logo
        /// </summary>
        public string PlatformLogo { get; set; }
        /// <summary>
        /// 办公地址
        /// </summary>
        public string OfficeAddress { get; set; }
        /// <summary>
        /// 创始人
        /// </summary>
        public string Founder { get; set; }
        /// <summary>
        /// 上线时间
        /// </summary>
        public DateTime OnlineTime { get; set; }
        /// <summary>
        /// 注册资本(万元)
        /// </summary>
        public int RegCapital { get; set; }
        /// <summary>
        /// IPC备案
        /// </summary>
        public string IPC { get; set; }
        /// <summary>
        /// 公司规模
        /// </summary>
        public string Scale { get; set; }
        /// <summary>
        /// 在线客服
        /// </summary>
        public string ServiceQQ { get; set; }
        /// <summary>
        /// 服务电话
        /// </summary>
        public string ServicePhone { get; set; }
        /// <summary>
        /// 总成交量
        /// </summary>
        public int TotalVolume { get; set; }
        /// <summary>
        /// 投资总人数
        /// </summary>
        public int TotalInvestors { get; set; }
        /// <summary>
        /// 成交周期
        /// </summary>
        public int DealTime { get; set; }
        /// <summary>
        /// 项目估值
        /// </summary>
        public int valuation { get; set; }
        /// <summary>
        /// 成交数量
        /// </summary>
        public int DealNum { get; set; }
        /// <summary>
        /// 平台简介
        /// </summary>
        public string PlatformPDL { get; set; }
        /// <summary>
        /// 状态
        /// </summary>
        public int Status { get; set; }
        /// <summary>
        /// 创建人
        /// </summary>
        public int CreatedUserID { get; set; }
        /// <summary>
        /// 添加时间
        /// </summary>
        public DateTime CreateDate { get; set; }
        /// <summary>
        /// 最新更新人
        /// </summary>
        public int UpdateUserID { get; set; }
        /// <summary>
        /// 修改时间
        /// </summary>
        public DateTime UpdateDate { get; set; }
        #endregion

        /// <summary>
        /// 名字的第一个字的首字母
        /// </summary>
        public string PlatformNameFirstInitial
        {
            get
            {
                string result = "";
                if (PlatformNameInitial.Length > 0)
                    result = PlatformNameInitial.Substring(0, 1);
                return result;
            }
        }
        /// <summary>
        /// 名字的第一个字的首字母
        /// </summary>
        public string GetOnlineTimeYear
        {
            get
            {
                string result = "";
                if (OnlineTime != null)
                    result = OnlineTime.ToString("yyyy");
                return result;
            }
        }

        #region 拓展属性
        /// <summary>
        /// 省份名称
        /// </summary>
        public string ProName { get; set; }
        /// <summary>
        /// 城市名称
        /// </summary>
        public string CityName { get; set; }
        #endregion

    }

拓展方法(网上COPY的)

[Serializable]
    public class FastPropertyComparer<T> : IEqualityComparer<T>
    {
        private Func<T, Object> getPropertyValueFunc = null;
        /// <summary>
        /// 通过propertyName 获取PropertyInfo对象
        /// </summary>
        /// <param name="propertyName"></param>
        public FastPropertyComparer(string propertyName)
        {
            PropertyInfo _PropertyInfo = typeof(T).GetProperty(propertyName,
            BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public);
            if (_PropertyInfo == null)
            {
                throw new ArgumentException(string.Format("{0} is not a property of type {1}.",
                    propertyName, typeof(T)));
            }
            ParameterExpression expPara = Expression.Parameter(typeof(T), "obj");
            MemberExpression me = Expression.Property(expPara, _PropertyInfo);
            getPropertyValueFunc = Expression.Lambda<Func<T, object>>(me, expPara).Compile();
        }
        #region IEqualityComparer<T> Members
        public bool Equals(T x, T y)
        {
            object xValue = getPropertyValueFunc(x);
            object yValue = getPropertyValueFunc(y);
            if (xValue == null)
                return yValue == null;
            return xValue.Equals(yValue);
        }
        public int GetHashCode(T obj)
        {
            object propertyValue = getPropertyValueFunc(obj);
            if (propertyValue == null)
                return 0;
            else
                return propertyValue.GetHashCode();
        }
        #endregion
    }

http://www.jb51.net/article/36773.htm

时间: 2024-08-02 06:58:10

Linq Distinct 指定属性过滤的相关文章

手把手教你如何用java8新特性将List中按指定属性排序,过滤重复数据

在java中常常会遇到这样一个问题,在实际应用中,总会碰到对List排序并过滤重复的问题,如果List中放的只是简单的String类型过滤so easy,但是实际应用中并不会这么easy,往往List中放的是一个类,类中有多个属性,要过滤重复数据,而且这个重复数据要按自己指定的属性过滤,但是要想按照其它属性排序顺序过滤,所以要先排序一下,然后按照某个属性过滤. 实体类如下所示,大家只要创建下面的实体类,无需继承父类,大家不会注解式风格的话,请自行加上getter/setter方法. 首先看看gr

SharePoint 2013/2010 根据当前用户的某个属性过滤搜索结果

本文讲述如何在SharePoint 2013/2010 中根据当前用户的某个属性过滤搜索结果. 最近客户有一个需求,就是根据用户所在的国家(User Info List里面有Country字段),在搜索时只显示该用户所在国家的记录(对应的list 有Country 字段). 一般来说SharePoint 搜索是根据当前用户的权限来决定是否可以搜索到对应的记录,但是过是这样的话,需要将列表的所有记录都打破权限记录,这是非常损耗性能的,而且这样的权限结构维护起来很复杂. 本文将使用 ISecurit

JQuery选择器学习整理(基本选择器,层级选择器,伪类选择器,属性过滤,内容过滤,可见性过滤,范围选择器,排除选择器)

总的来说,选择器引擎规则就是: $('查询字符串'). 最常用最基本的就是:1.标签选择器(以文档元素作为选择符):$("div"): 2.id选择器(以ID作为选择符): $("#demo1"): 3.类选择器(以class作为选择符): $(".selected"): 4.群组选择器: $(".class1, .class2, .class3"): 5.后代选择器: $("p span") 多种规则的组

jQuery之属性过滤选择器

转自:http://blog.csdn.net/woshisap/article/details/7341136 在HTML文档中,元素的开始标记中通常包含有多个属性(attribute), 在jQuery中,除了直接使用id和class属性作为选择器之外,还可以根据各种属性(如title等)对由选择器 查询到的元素进行过滤,属性过滤选择器包含了在中括号"[]"中,而不是以冒号开头,通常使用"选择器[属性过滤选择器]"语法格式,可以根据是否包含指定属性或者 根据属性

黑马day16 jquery&amp;属性过滤选择器

属性过滤选择器的过滤规则是通过元素的属性来获取相应的元素 1.[attribute] 用法: $("div[id]") ;  返回值  集合元素 说明:匹配包含给定属性的元素.例子中是选取了所有带"id"属性的div标签. 2.[attribute=value] 用法: $("input[name='newsletter']").attr("checked", true);    返回值  集合元素 说明:匹配给定的属性是某个

JQuery属性过滤(转)

属性过滤(Attribute Filters)的内容就是html元素中的属性 其包括以下几个选择器: [attribute] [attribute=value] [attribute!=value] [attribute^=value] [attribute$=value] [attribute*=value] [attributeFilter1][attributeFilter2][attributeFilterN] [attribute]用法: $(“div[id]“) ;说明: 匹配包含给

对JavaScript对象数组按指定属性和排序方向进行排序

引子 在以数据为中心的信息系统中,以表格形式展示数据是在常见不过的方式了.对数据进行排序是必不可少的功能.排序可以分为按单个字段排序和按多个字段不同排序方向排序.单字段排序局限性较大,不能满足用户对数据的关注点变化的需求,而多字段排序就可以较好的弥补这个缺陷. 多字段排序,实现的方式从大的层面上可以分为后端实现和前端实现. 后端排序 后端实现排序可以在数据库层面实现或者在应用程序层面实现. 数据库层面实现多字段排序非常简单,使用SQL的排序指令“Order By”即可——Order By fie

Maven3_maven移植和属性过滤

maven移植-级别 不可移植 环境可移植 组织内部可移植 广义可移植 Maven移植-Profiles作用是:Profile允许你为移植或特殊的需要,自定义一个特殊的构建. 1.maven移植-Profiles位于pom.xml Profile可以覆盖几乎所有的pom元素 <profile> <build> <defaultGoal>...</defaultGoal> <finalName>...</finalName> <r

一步一步学习 JQuery (四) 过滤选择器:属性过滤选择器 &amp;&amp; 子元素过滤选择器 &amp;&amp; 表单过滤选择器

四.属性过滤选择器 属性过滤选择器的过滤规则是通过元素的属性来获取相应的元素 选取下列元素,改变其背景色为 # bbffaa 含有属性title 的div元素. 属性title值等于"test"的div元素. 属性title值不等于"test"的div元素(没有属性title的也将被选中). 属性title值 以"te"开始 的div元素. 属性title值 以"est"结束 的div元素. 属性title值 含有"