Composite Id kullanımı hakkında

90 views
Skip to first unread message

ilgiz SEBER

unread,
Nov 19, 2009, 10:25:27 AM11/19/09
to altdotne...@googlegroups.com
Merhaba,

NHibernate 'te composite id kullanımı hakkında bir sorum olacak.

Composite Id'lerin bulunduğu class içerisinde neden System.Object sınıfının metodları olan Equals() ve GetHashCode() metodlarını override etmek durumunda kalıyoruz?

Benim uygulamamda composite id'lerimi belirttiğim ilgili Class'ım şu: 

public class EmployeeTerritories
    {
        private Employees employeeId;
        private Territories territoryId;

        public virtual Employees EmployeeID
        {
            get { return employeeId; }
            set { employeeId = value; }
        }

        public virtual Territories TerritoryID
        {
            get { return territoryId; }
            set { territoryId = value; }
        }

        public override int GetHashCode()
        {
            int hashCode = 0;
            hashCode = hashCode ^ EmployeeID.GetHashCode() ^ TerritoryID.GetHashCode();
            return hashCode;
        }

        public override bool Equals(object obj)
        {
            var toCompare = obj as EmployeeTerritories;
            if(toCompare == null)
            {
                return false;
            }

            return (this.GetHashCode() != toCompare.GetHashCode());
        }
    }

Saygılarımla.

--
İlgiz SEBER
Software Developer

Karash Software & Security Technologies
Mobile: +90 533 2819232
Phone: +90 216 3262501
Fax: +90 216 3261607

Murat HAKSAL

unread,
Nov 19, 2009, 11:08:24 AM11/19/09
to altdotne...@googlegroups.com
Selam bu sadece composite Id kullanılan nesneler için değil,nh da kullanılan  tüm modeller için geçerlidir,
ancak composite olmayan modeller için default bir davranışı var, composite ise hangi Id ye bakıcanı bilemiyor.
Db den gelen nesne  ile NH session daki nesnenin aynı nesne olması için.(Compare)

Kolay Gelsin.

MH

19 Kasım 2009 17:25 tarihinde ilgiz SEBER <ise...@gmail.com> yazdı:

--

You received this message because you are subscribed to the Google Groups "altdotnetturkiye" group.
To post to this group, send email to altdotne...@googlegroups.com.
To unsubscribe from this group, send email to altdotnetturki...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/altdotnetturkiye?hl=.

Reply all
Reply to author
Forward
0 new messages