Using uCommerce v6.6, Umbraco v7
I'm having trouble setting the category's display name and a custom definition that I have created.
I'm receiving this error:
not-null property references a null or transient value UCommerce.EntitiesV2.Category.ProductCatalog
I think this is b/c there's a property in the CategoryDescription class,
public virtual int CategoryDescriptionId { get; protected set; }
But I don't know how to set this b/c usually when you create objects like this, once you save an ID is created for you (think EF).
Also I'm needing to set the custom definition for the category, "productNumber".
var parentCategory = catalog.Categories.First(x => x.Name.Equals(parentName));
var newCategory = new Category
{
Name = product.Name,
Definition = productDef,
DisplayOnSite = true,
ParentCategory = parentCategory,
ProductCatalog = catalog
};
catalog.Categories.Add(newCategory);
catalog.Save();
var catDescription = new CategoryDescription()
{
DisplayName = product.GetValue<string>("productName"),
Category = newCategory,
};
catDescription.Save(); // ****errors out here*****
var catProperty = new CategoryProperty()
{
Category = newCategory,
DefinitionField = DefinitionField.FirstOrDefault(x => x.Name.Equals("productNumber")),
Value = product.GetValue<string>("productNumber"),
};
catProperty.Save();
All my variables have data, meaning they're not null. It's on the save that's the null. newCategory is successfully created as well each and every time.
Class def for CategoryDescription
public class CategoryDescription : IEntity
{
public CategoryDescription();
public static bool operator !=(CategoryDescription x, CategoryDescription y);
public static bool operator ==(CategoryDescription x, CategoryDescription y);
public virtual Category Category { get; set; }
public virtual int CategoryDescriptionId { get; protected set; }
public virtual int? ContentId { get; set; }
public virtual string CultureCode { get; set; }
public virtual string Description { get; set; }
public virtual string DisplayName { get; set; }
public virtual int Id { get; }
public virtual bool RenderAsContent { get; set; }
public static IQueryable<CategoryDescription> All();
public virtual void Delete();
public static void Delete(Expression<Func<CategoryDescription, bool>> expression);
public override bool Equals(object obj);
public static bool Exists(Expression<Func<CategoryDescription, bool>> expression);
public static IList<CategoryDescription> Find(Expression<Func<CategoryDescription, bool>> expression);
public static CategoryDescription FirstOrDefault(Expression<Func<CategoryDescription, bool>> expression);
public static CategoryDescription Get(object id);
public override int GetHashCode();
public virtual void Save();
public static CategoryDescription SingleOrDefault(Expression<Func<CategoryDescription, bool>> expression);
}