Quantcast
Channel: Developer to developer
Viewing all articles
Browse latest Browse all 9076

Programmatically adding category to a page results in CategoryType equal to 0

$
0
0

Hi,

I need to programmatically create some pagetypes that have a CategoryList property in them. 

I add some categories to this list, but when checking the database table 'tblContentCategory' the fields 'CategoryType' and 'ScopeName' are equal to 0.

The 'fkCategoryID' is filled in correctly however. 

Those zeroes are probably the reason that the CategoryList field on the admin-side is empty although there are categories associated with the page since there are rows in 'tblContentCategory'.

When I add another instance of that new page-type programmatically and check that table again, I see one new row for each category (same categories I used when creating them programmatically) in this categorylist where the fields 'CategoryType' and 'ScopeName' are not equal to 0 but filled in correctly.

What could be the cause for this?

Here's a code snippet of how I create my page

            var categoryRepository = _serviceLocator.GetInstance();
....
                    var faqQuestionPage = _contentRepository.GetDefault(faqSettingsPage.ContentLink);
....
var shipping = categoryRepository.Get("Shipping");
faqQuestionPage.Category.Add(shipping.ID);
....
_contentRepository.Save(faqQuestionPage, EPiServer.DataAccess.SaveAction.Publish, AccessLevel.NoAccess);

And here a snippet of how I create categories, the categories are created and saved before the questions are generated.

var categoryRepository = _serviceLocator.GetInstance();
            var parentCategory = categoryRepository.Get("Faq");
var shippingCategory = new Category(parentCategory, "Shipping")
            {
                Selectable = true,
                Description = "Shipping"
            };
categoryRepository.Save(shippingCategory);

Viewing all articles
Browse latest Browse all 9076

Trending Articles