Breeze,js error Collection navigation properties may NOT be set

∥☆過路亽.° 提交于 2019-12-24 08:57:25

问题


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?


回答1:


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?



来源:https://stackoverflow.com/questions/14902352/breeze-js-error-collection-navigation-properties-may-not-be-set

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!