public static void CheckDeleteAddress <TAddressEntity, TLocationReferenceEntity>(this IHaveAddressEntities <TAddressEntity, TLocationReferenceEntity> haveAddressEntities, IHaveAddress haveAddress, IHaveAddressEntity <TAddressEntity, TLocationReferenceEntity> entity) where TAddressEntity : class, IAddressEntity <TLocationReferenceEntity> where TLocationReferenceEntity : class, ILocationReferenceEntity { // If there was an address but there is none now then delete. if (entity.AddressEntity != null && haveAddress.Address == null) { if (entity.AddressEntity.LocationReferenceEntity != null) { haveAddressEntities.LocationReferenceEntities.DeleteOnSubmit(entity.AddressEntity.LocationReferenceEntity); } haveAddressEntities.AddressEntities.DeleteOnSubmit(entity.AddressEntity); entity.AddressEntity = null; } }
public static void MapTo <TAddressEntity, TLocationReferenceEntity>(this IHaveAddress haveAddress, IHaveAddressEntity <TAddressEntity, TLocationReferenceEntity> entity) where TAddressEntity : class, IAddressEntity <TLocationReferenceEntity>, new() where TLocationReferenceEntity : class, ILocationReferenceEntity, new() { if (haveAddress.Address != null) { if (entity.AddressEntity == null) { entity.AddressEntity = haveAddress.Address.MapTo <TAddressEntity, TLocationReferenceEntity>(); } else { haveAddress.Address.MapTo(entity.AddressEntity); } } }