nave

nave

  • NA
  • 31
  • 0

How to update foreign key back to NULL?

Oct 21 2013 5:54 AM
How do i update a foreign key column back to null?

On insert or update i use this:

getCategory = _db.Categories.Find(id);
Events.Categories = getCategory; //add foreign key

But if the category is 0 (not selected) i want to update the relationship Category_ID back to null.

Try to do it like that:

Events.Categories = null; //add foreign key

But it doesn't seems to work

Please advise
Thanks

Answers (2)