Address.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace PatientEntities | |
{ | |
public partial class Address | |
{ | |
#region Primitive Properties | |
public virtual long AddressId | |
{ | |
get; | |
set; | |
} | |
public virtual string Line1 | |
{ | |
get; | |
set; | |
} | |
public virtual string Line2 | |
{ | |
get; | |
set; | |
} | |
public virtual string Line3 | |
{ | |
get; | |
set; | |
} | |
public virtual string Line4 | |
{ | |
get; | |
set; | |
} | |
public virtual string City | |
{ | |
get; | |
set; | |
} | |
public virtual string StateProvince | |
{ | |
get; | |
set; | |
} | |
public virtual string PostalCode | |
{ | |
get; | |
set; | |
} | |
public virtual string Country | |
{ | |
get; | |
set; | |
} | |
public virtual string OtherAddressDetails | |
{ | |
get; | |
set; | |
} | |
#endregion | |
#region Navigation Properties | |
public virtual ICollection<Patient> Patients | |
{ | |
get | |
{ | |
if (_patients == null) | |
{ | |
var newCollection = new FixupCollection<Patient>(); | |
newCollection.CollectionChanged += FixupPatients; | |
_patients = newCollection; | |
} | |
return _patients; | |
} | |
set | |
{ | |
if (!ReferenceEquals(_patients, value)) | |
{ | |
var previousValue = _patients as FixupCollection<Patient>; | |
if (previousValue != null) | |
{ | |
previousValue.CollectionChanged -= FixupPatients; | |
} | |
_patients = new FixupCollection<Patient>(value); | |
var newValue = value as FixupCollection<Patient>; | |
if (newValue != null) | |
{ | |
newValue.CollectionChanged += FixupPatients; | |
} | |
} | |
} | |
} | |
private ICollection<Patient> _patients; | |
#endregion | |
#region Association Fixup | |
private void FixupPatients(object sender, NotifyCollectionChangedEventArgs e) | |
{ | |
if (e.NewItems != null) | |
{ | |
foreach (Patient item in e.NewItems) | |
{ | |
item.Address = this; | |
} | |
} | |
if (e.OldItems != null) | |
{ | |
foreach (Patient item in e.OldItems) | |
{ | |
if (ReferenceEquals(item.Address, this)) | |
{ | |
item.Address = null; | |
} | |
} | |
} | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment