Hello,
I have a parent child relationship very similar to Northwind Customer/Orders but with one differnece , CustomerID in Orders table can not accept NULL , it is a FK , the child has one column PKey called OrderID
I use this model in a windows forms databinding , upper area is having customer info in text boxes , lower area is having a grid with orders listed
I retrieve a customer using LINQ from DB to allow the user to edit customer info or order details , when i delete a row from the order grid then submit changes , i receive error "An Attempt was made to remove a relationship Between a Customer and Orders, However , one of the relationship's foreign keys (CustomerID) can't be set to Null"
after a long search on the internet , i used the DeleteOnNull=True attribute and it now works
What is not working however and still give same exact error is when i add a new order to the grid then delete it before SubmitChanges
I understand that when i delete a new order row in the grid i only remove the association to customer, so it sets CustomerID=NULL for that entity , fine , now how do it remove it entirely from the entity set before submit changes to avoid the error , i can't use DeleteOnSubmit because it is a new entity not came from db , i will receive an exception if i tried , so deleting the row by hand using the grid does not work which is calling "Remove" method i guess , and i can't use DeleteOnSubmit , what can i do ?
why it has to be that difficult? at ADO.NET datatable is much easier, if i delete a row and it happends to come from db then it marks it for deletion, if it is a new row then it removes it from the collection, Done! i don't want to go back to Datasets after investing many efforts learning LINQ to SQL now
any help is very appreciated
Thank you Bassam