This is a migrated thread and some comments may be shown as answers.

About group by object

4 Answers 82 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
lin
Top achievements
Rank 1
lin asked on 13 Jul 2010, 06:39 AM
I bind an object to a column. My object's base class has implement IComparable and IEquatable. But when group by this object, it's result is error. Same object can't group into one group. If I set the binding path to object name property, the result is correct, but the editor for this object can't work.
What else can I do ?

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 13 Jul 2010, 06:44 AM
Hi,

 Can you post the code for this object and what kind of error you get when you try to group?

Best wishes,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
lin
Top achievements
Rank 1
answered on 13 Jul 2010, 07:08 AM

My grid's ItemsSource class Is User. User has a property DefaultDepartment. User and Department is inherit from Actor. Actor inherit from SystemObject. Class SystemObject implement IComparable and IEquatable. The group result is error. for example, User A and B has same DefaultDepartment, but when group by DefaultDepartment, User A and B is not in same group.In fact, each user  is in a group. My object is here:

public class User : Actor
    {
        public User()
            : base()
        {
              
        }
  
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="newId">用户ID</param>
        public User(Guid newId)
            : this()
        {
            Id = newId;
        }
  
    [DataMember]
        public virtual Department DefaultDepartment
        {
            get { return _defaultDepartment; }
            set { _defaultDepartment = value; }
        }
  
    }
  
  
public class Department : Actor
    {
        public Department()
            : base()
        {
            parentId = Guid.Empty;
            _actorType = this.GetType().Name;
        }
  
        public Department(Guid nid)
            : this()
        {
            Id = nid;
        }
  
        private User _departmentOwner;
  
        /// <summary>
        /// 部门负责人
        /// </summary>
        [DataMember]
        public virtual User DepartmentOwner
        {
            get { return _departmentOwner; }
            set { _departmentOwner = value; }
        }
          
    }
  
       
public class Actor : KingFuture.KFBase.SystemObject
    {
          
        public Actor()
            : base()
        {
            _actorType = "";
        }
  
  
        public Actor(Guid actorId) 
            : this()
        {
            Id = actorId;
        }
  
        protected string _actorType;
  
        /// <summary>
        /// 类型,值:User、Department、Role、Position
        /// </summary>
        [DataMember]
        public virtual string ActorType
        {
            get { return _actorType; }
            set { _actorType = value; }
        }
  
    }
  
  
  
  
public class SystemObject : IComparable, IEquatable<SystemObject>
    {
        public SystemObject()
        {
              
        }
  
        public SystemObject(Guid objId)
            : this()
        {
            _id = objId;
        }
  
        protected Guid _id;
  
        /// <summary>
        /// 对象ID
        /// </summary>
        [DataMember]
        public virtual Guid Id
        {
            get { return _id; }
            set { _id = value; }
        }
        protected string _name;
  
        /// <summary>
        /// 对象名称
        /// </summary>
        [DataMember]
        public virtual string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        protected string _code;
  
        /// <summary>
        /// 对象编号
        /// </summary>
        [DataMember]
        public virtual string Code
        {
            get { return _code; }
            set { _code = value; }
        }
  
  
        protected string _description;
  
        /// <summary>
        /// 对象备注说明
        /// </summary>
        [DataMember]
        public virtual string Description
        {
            get { return _description; }
            set { _description = value; }
        }
  
        protected DateTime _createDate = DateTime.Now;
  
        /// <summary>
        /// 对象创建日期
        /// </summary>
        [DataMember]
        public virtual DateTime CreateDate
        {
            get { return _createDate; }
            set { _createDate = value; }
        }
        protected Guid _createUserId;
  
        /// <summary>
        /// 对象创建人
        /// </summary>
        [DataMember]
        public virtual Guid CreateUserId
        {
            get { return _createUserId; }
            set { _createUserId = value; }
        }
  
        protected DelFlag _delFlag = DelFlag.Normal;
  
        /// <summary>
        /// 对象删除标记
        /// </summary>
        [DataMember]
        public virtual DelFlag DelFlag
        {
            get { return _delFlag; }
            set { _delFlag = value; }
        }
  
        private DateTime _deleteTime = DateTime.MaxValue;
  
        /// <summary>
        /// 逻辑删除时间
        /// </summary>
        [DataMember]
        public virtual DateTime DeleteTime
        {
            get { return _deleteTime; }
            set { _deleteTime = value; }
        }
  
          
  
        public override string ToString()
        {
            return _name;
        }
  
        private Guid _companyId;
  
        /// <summary>
        /// 对象所属公司ID
        /// </summary>
        [DataMember]
        public virtual Guid CompanyId
        {
            get { return _companyId; }
            set { _companyId = value; }
        }
  
        private Guid _siteId;
  
        /// <summary>
        /// 对象所属网站ID
        /// </summary>
        [DataMember]
        public virtual Guid SiteId
        {
            get { return _siteId; }
            set { _siteId = value; }
        }
  
        private int _displayOrder;
  
        /// <summary>
        /// 显示顺序
        /// </summary>
        [DataMember]
        public virtual int DisplayOrder
        {
            get { return _displayOrder; }
            set { _displayOrder = value; }
        }
  
  
        #region IComparable 成员
  
        public virtual int CompareTo(object obj)
        {
            if (obj != null && obj is SystemObject)
            {
                SystemObject so = (SystemObject)obj;
                if (so.Id == this.Id)
                    return 0;
                else
                    return this.Name.CompareTo(so.Name);
            }
  
            throw new Exception("Object is not SystemObject, Cann't Compare!");
        }
  
        #endregion

        #region IEquatable<SystemObject> Members

        public bool Equals(SystemObject other)
        {
            return other != null && this.Id == other.Id;
        }

        #endregion


}
0
Accepted
Tsvyatko
Telerik team
answered on 16 Jul 2010, 08:28 AM
Hi lin,

I have investigated the problem you have encountered and here are the results:

 - Your object implements IEquitable<T> not directly, but inheriting it from the parent. Moreover, it implements IEquitable<SystemObject> rather than IEquitable<Department>. However, there is one specific of the framework -  GroupBy extension method (we use it internally) checks for suitable IEquitable implementation using IsAssignableFrom method, which does not resolve parent interfaces.

In short in order to fit this specifics the following modifications is needed:
public class Department : Actor, IEquatable<Department>

Please check the attachment and let me know if you need any further assistance.

All the best,
Tsvyatko
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
lin
Top achievements
Rank 1
answered on 16 Jul 2010, 08:54 AM
It do work, thank a lot.
Tags
GridView
Asked by
lin
Top achievements
Rank 1
Answers by
Vlad
Telerik team
lin
Top achievements
Rank 1
Tsvyatko
Telerik team
Share this question
or