|
| 1 | +using System; |
| 2 | + |
| 3 | + |
| 4 | +namespace NHibernate.Test.NHSpecificTest.GH1496 |
| 5 | +{ |
| 6 | + // Entity with ManyToOne type (Address) with regular (int) Id |
| 7 | + public class Person |
| 8 | + { |
| 9 | + public virtual int Id { get; set; } |
| 10 | + |
| 11 | + public virtual string Name { get; set; } |
| 12 | + |
| 13 | + public virtual Address Address { get; set; } |
| 14 | + |
| 15 | + public Person() |
| 16 | + { |
| 17 | + } |
| 18 | + |
| 19 | + public Person(int id, string name, Address address) |
| 20 | + { |
| 21 | + Id = id; |
| 22 | + Name = name; |
| 23 | + Address = address; |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + // Entity with ManyToOne type (Contact) with comnposite (ContactId) Id. |
| 28 | + public class Employee |
| 29 | + { |
| 30 | + public virtual int Id { get; set; } |
| 31 | + |
| 32 | + public virtual string Name { get; set; } |
| 33 | + |
| 34 | + public virtual Contact Contact { get; set; } |
| 35 | + |
| 36 | + public Employee() |
| 37 | + { |
| 38 | + } |
| 39 | + |
| 40 | + public Employee(int id, string name) |
| 41 | + { |
| 42 | + Id = id; |
| 43 | + Name = name; |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + |
| 48 | + public class Address |
| 49 | + { |
| 50 | + public virtual int Id { get; set; } |
| 51 | + public virtual string PostalCode { get; set; } |
| 52 | + |
| 53 | + public virtual string State { get; set; } |
| 54 | + |
| 55 | + public virtual string Street { get; set; } |
| 56 | + |
| 57 | + public Address() |
| 58 | + { } |
| 59 | + |
| 60 | + public Address(string postalCode, string state, string street) |
| 61 | + { |
| 62 | + PostalCode = postalCode; |
| 63 | + State = state; |
| 64 | + Street = street; |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + [Serializable] |
| 70 | + public class Contact |
| 71 | + { |
| 72 | + public virtual ContactIdentifier ContactIdentifier { get; set; } |
| 73 | + public virtual string Phone { get; set; } |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | + public class ContactIdentifier : IEquatable<ContactIdentifier> |
| 78 | + { |
| 79 | + public virtual string TypeName { get; set; } |
| 80 | + public virtual string ContactId { get; set; } |
| 81 | + |
| 82 | + public ContactIdentifier(string typeName, string contactId) |
| 83 | + { |
| 84 | + ContactId = contactId; |
| 85 | + TypeName = typeName; |
| 86 | + } |
| 87 | + |
| 88 | + public ContactIdentifier() { } |
| 89 | + |
| 90 | + public virtual bool Equals(ContactIdentifier other) |
| 91 | + { |
| 92 | + if (ReferenceEquals(null, other)) return false; |
| 93 | + if (ReferenceEquals(this, other)) return true; |
| 94 | + return string.Equals(TypeName, other.TypeName) && string.Equals(ContactId, other.ContactId); |
| 95 | + } |
| 96 | + |
| 97 | + public override bool Equals(object obj) |
| 98 | + { |
| 99 | + if (ReferenceEquals(null, obj)) return false; |
| 100 | + if (ReferenceEquals(this, obj)) return true; |
| 101 | + if (obj.GetType() != this.GetType()) return false; |
| 102 | + return Equals((ContactIdentifier) obj); |
| 103 | + } |
| 104 | + |
| 105 | + public override int GetHashCode() |
| 106 | + { |
| 107 | + unchecked |
| 108 | + { |
| 109 | + return ((TypeName != null ? TypeName.GetHashCode() : 0) * 397) ^ (ContactId != null ? ContactId.GetHashCode() : 0); |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + public static bool operator ==(ContactIdentifier left, ContactIdentifier right) |
| 114 | + { |
| 115 | + return Equals(left, right); |
| 116 | + } |
| 117 | + |
| 118 | + public static bool operator !=(ContactIdentifier left, ContactIdentifier right) |
| 119 | + { |
| 120 | + return !Equals(left, right); |
| 121 | + } |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | + } |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | +} |
0 commit comments