Alex Maie
Alex Maie

Reputation: 269

Breeze,js error Collection navigation properties may NOT be set

I am receiving the this error when i try to add a new object to the navigation Collection navigation properties may NOT be set.

This is my POCO:

 public class Category : BaseEntity,IDeletable
{
    public Category()
    {
        Products = new List<Product>();
        ChildCategories = new List<Category>();
    }


    [Required]
    [Display(ResourceType = typeof(DelkaShop.Entities.EntityText.EntityText), Name = "EntityName")]
    public String Name { get; set; }

    [Display(ResourceType = typeof(DelkaShop.Entities.EntityText.EntityText), Name = "ParentCategory")]
    public int? ParentCategoryId { get; set; }

    [Display(ResourceType = typeof(DelkaShop.Entities.EntityText.EntityText), Name = "ItemsPerPage")]
    public int? ItemsPerPage { get; set; }

    [InverseProperty("Categories")]
    public ICollection<Product> Products { get; set; }

    [ForeignKey("ParentCategoryId")]
    [Display(ResourceType = typeof(DelkaShop.Entities.EntityText.EntityText), Name = "ParentCategory")]
    public  Category ParentCategory { get; set; }

    public  ICollection<Category> ChildCategories { get; set; }

}

in breeze i am doing somehting like product.Categories.push(newCategoryObject);

Can somebody point me into the right direction?

EDIT: I forgot to mention that i am getting this error for a many to many relationship and just read in the documentation that this is not supported yet.

Is there by any chance a workaround?

Upvotes: 1

Views: 1070

Answers (1)

Ward
Ward

Reputation: 17863

I'm afraid that the only work-around is to expose the mapping between the two types as its own entity.

As I've said elsewhere, I'm not fond of hiding the mapping object behind the EF m-to-m association. That disguise always seems to create far more trouble than it is worth. The moment that the mapping gains a payload - a link-date, version, tenant-identifier - anything - the m-to-m falls apart and the mapping object must be defined. That "moment" arrives sooner or later in my experience. The later it arises, the more trouble it causes. So I recommend exposing it now while the cost is low. Is that possible for you?

Upvotes: 3

Related Questions