2

I have 2 tables:

orders 
orderItems

connected to one another threw a relationship(FK orderId in the orderItems table). is there a difference between:

order.orderitems.remove(...) 

to just setting the orderId value to null when trying to remove the related entity?

1
  • 1
    Hw90's answer is wrong. There is no difference between the two things you are doing. Commented Apr 24, 2012 at 17:12

1 Answer 1

2

Setting the FK property to null and removing the entity from the navugation property both do the same thing. That is, they both sever the relationship between the entities but do not cause either entity to be deleted. It's the same as setting the FK value in the database to NULL.

To delete the entity you must call Remove on the DbSet for the entity. For example

context.OrderItems.Remove(orderitem);
context.SaveChanges();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.