I’m using EF code-first and I have a question…
I have 2 objects: Product and Category. In the Product object I have a CategoryId property and also a Category property.
My question is, if I want to update a category in the product object, which property should I change? The CategoryId or the Category?
I’m updating both at the moment, but it seems a bit weird to me…
thanks!
Simplest way is just:
That’s all, you don’t need to load nor set the navigation property. This simple code is one of the reasons why foreign key properties (like
CategoryId) are useful.