views:

24

answers:

1

Hi,

I have a SalesOrder table and a separate Address table. The SalesOrder has two addresses - thus avoiding use of a list, there are the Delivery and Invoice address. This is how they have been mapped in the SalesOrder mapping file:

<many-to-one name="DeliveryAddress" class="Address" column="`DeliveryAddressGUID`" />
<many-to-one name="InvoiceAddress" class="Address" column="`InvoiceAddressGUID`" />

Is it actually possible to have this relationship - where two separate fields in the same table reference another. If I remove one of the "many-to-one" associations, I can add Address to the table, otherwise if I keep both associations I get the following exception:

"The UPDATE statement conflicted with the FOREIGN KEY constraint \"FK67C9F3E2FBD32E03\". The conflict occurred in database \"Dispatch\", table \"dbo.Address\", column 'GUID'.\r\nThe statement has been terminated."

Am I doing something wrong?

Thanks

Edit These are the relevant parts of the two tables:

SalesOrder
------------
Guid
DeiveryAddressGuid
InvoiceAddressGuid
...

Address
------------
Guid
HouseNameOrNumber
AddressLine1
AddressLine2
...

The error is really strange since it won't let me simply add an address to the Address table by itself with both Foreign Keys active (this is in NHibernate, I've not been able to test this directly with SQL Server).

+1  A: 

did you check to make sure both of those entries where in the parent table?

DForck42
I assumed that cascading was doing this already, obviously not. Thanks for your help.
Tony Day
Sometimes it the simpliest things.
DForck42