Hello!
I'm trying to implement XML import option to my nopCommerce store.
XML has nice integer ID's for categories, so I turned off autonumber option for dbo.Category table in database.
Now, I'm getting exception:
Cannot insert the value NULL into column 'Id', table 'nopCommerce.dbo.Category'; column does not allow nulls. INSERT fails.
The statement has been terminated.
My XML:
<cat>
<id>17</id>
<name>Category name</name>
<parent_id>0</parent_id>
</cat>
My code:
var category = _categoryService.GetCategoryById(Id);
if (category != null)
{
category.Name = model.Name;
category.ParentCategoryId = model.ParentCategoryId;
category.UpdatedOnUtc = DateTime.UtcNow;
category.Published = true;
category.Deleted = false;
_categoryService.UpdateCategory(category);
}
else
{
category = new Core.Domain.Catalog.Category();
category.Id = model.Id;
category.ParentCategoryId = model.ParentCategoryId;
category.Name = model.Name;
category.UpdatedOnUtc = DateTime.UtcNow;
category.CreatedOnUtc = DateTime.UtcNow;
category.Published = true;
category.Deleted = false;
_categoryService.InsertCategory(category);
}