Search code examples
c#ormforeign-keysrdbmsormlite-servicestack

Insert conflict with foreign key constraint


I am building an API with OrmLite from ServiceStack.


When populating it with test data I get the following error:

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Order_Customer_CustomerId". The conflict occurred in database "C:\USERS\ALECTAYLOR\SOCIALBOOTSTRAPAPI\SRC\SOCIALBOOTSTRAPAPI\APP_DATA\USERAUTH.MDF", table "dbo.Customer", column 'Id'. The statement has been terminated.

Code (lines 213-236 + CreateOrders function): http://pastebin.com/Njhz7sD2

Profiler output: http://fiddle.jshell.net/cTen2/1/show/


Thanks for any advice on how to rectify this issue.


Solution

  • Alright, got it to work.

    Needed to set the ShopId of Order and orderId of the orderDetails List.

    http://pastebin.com/TbrW150T