If Category is set by assigning list, the value is not saved

Fixed in

EPiServer.CMS.Core 10.0.1

Created

Aug 26, 2015

Updated

Oct 27, 2016

Area

CMS Core

State

Closed, Fixed and tested


Description

The following code does not save categories to the database:

var content = ContentRepository.GetDefault<StandardPage>(ContentReference.StartPage);  
content.Name = "Category test";  
content.Category = new CategoryList(new[] { 2 })*; // Where a category with ID 2 exist.
 
contentRepository.Save(content, SaveAction.Publish);

But this one does:

var content = ContentRepository.GetDefault<StandardPage>(ContentReference.StartPage);  
content.Name = "Category test";  
content.Category.Add(2); 
contentRepository.Save(content, SaveAction.Publish);

The problem is that a CategoryList (where values are set in the constructor) is not considered modified, and this means that we do not save the values either.

The underlying PropertyData object will, in both cases, be considered modified if checked after the Category is modified.

content.Property[MetaDataProperties.PageCategory].IsModified == true;