Skip to content

Instantly share code, notes, and snippets.

@Vaccano
Created July 6, 2011 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vaccano/1068069 to your computer and use it in GitHub Desktop.
Save Vaccano/1068069 to your computer and use it in GitHub Desktop.
Address.cs
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