BreezeJs:从更改的BreezeController更新到新元数据

时间:2014-03-14 05:08:09

标签: entity-framework angularjs metadata breeze asp.net-web-api2

我已经更改并向我的服务器端类添加了一些属性,但无法在我的breeze / angular应用程序中获取更新的数据。添加的字段保持空白而不是显示值。我也无法创建我添加的实体。 (错误)。如何在breeze / angular应用程序中更新元数据以使用最新版本?我试图获取元数据,但获取已经获取的消息。

Breeze: Unable to locate a 'Type' by the name: 'New Class'. Be sure to execute a query or call fetchMetadata first

更新(更多信息)


我创建了一个与Product类相关的子类。它被称为ProductStockItem,因此产品有许多ProductStockItems。

ProductStockItem :(新课程)

public class ProductStockItem
{


    public int Id { get; set; }
    public int ProductId { get; set; }
    public string Size { get; set; }
    public int Quantity { get; set; }
    public bool UseStockQuantity { get; set; }
    public decimal PriceAdjustment { get; set; }
    public DateTime? DateAvailable { get; set; }
    public int DisplayOrder { get; set; }
    public bool Deleted { get; set; }
    public State State { get; set; }
    public DateTime? DateChanged { get; set; }
    public DateTime? DateCreated { get; set; }      

    public virtual Product Product { get; set; }

}

产品

public class Product
{    
    private ICollection<ProductCategory> _productCategories;
    private ICollection<ProductManufacturer> _productManufacturers;
    private ICollection<ProductPicture> _productPictures;
    private ICollection<ProductSpecificationAttribute> _productSpecificationAttributes;
    private ICollection<ProductStockItem> _productStockItems; 

    public int Id { get; set; }
    public ProductType ProductType { get; set; }
    public int ParentGroupedProductId { get; set; }
    public int ManufacturerSizeId { get; set; }
    public bool VisibleIndividually { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public string MetaTitle { get; set; }
    public string MetaDescription { get; set; }
    public int DisplayOrder { get; set; }
    public bool LimitedToStores { get; set; }
    public string Sku { get; set; }
    public string UniqueCode { get; set; }
    public decimal Price { get; set; }
    public decimal OldPrice { get; set; }
    public decimal? SpecialPrice { get; set; }
    public DateTime? SpecialPriceStartDateTimeUtc { get; set; }
    public DateTime? SpecialPriceEndDateTimeUtc { get; set; }
    public decimal DiscountPercentage { get; set; }
    public bool HasTierPrices { get; set; }
    public bool HasStock { get; set; }
    public TaxRate TaxRate { get; set; }
    public bool SyncToShop { get; set; }
    public bool Deleted { get; set; }
    public bool Locked { get; set; }
    public State State { get; set; }
    public DateTime? DateChanged { get; set; }
    public DateTime? DateCreated { get; set; }

    public virtual ICollection<ProductCategory> ProductCategories
    {
        get { return _productCategories ?? (_productCategories = new List<ProductCategory>()); }
        protected set { _productCategories = value; }
    }

    public virtual ICollection<ProductManufacturer> ProductManufacturers
    {
        get { return _productManufacturers ?? (_productManufacturers = new List<ProductManufacturer>()); }
        protected set { _productManufacturers = value; }
    }

    public virtual ICollection<ProductPicture> ProductPictures
    {
        get { return _productPictures ?? (_productPictures = new List<ProductPicture>()); }
        protected set { _productPictures = value; }
    }

    public virtual ICollection<ProductSpecificationAttribute> ProductSpecificationAttributes
    {
        get { return _productSpecificationAttributes ?? (_productSpecificationAttributes = new List<ProductSpecificationAttribute>()); }
        protected set { _productSpecificationAttributes = value; }
    }

    public virtual ICollection<ProductStockItem> ProductStockItems
    {
        get { return _productStockItems ?? (_productStockItems = new List<ProductStockItem>()); }
        protected set { _productStockItems = value; }
    }

 }

产品要求:

http://testdomain.local/breeze/DataContext/Products?$filter=Id%20eq%201029&$orderby=Id&$expand=ProductStockItems&

[{"$id":"1","$type":"Erp.Models.ErpModel.Catalog.Product, Erp.Models.ErpModel","Id":1029,"ProductType":"SimpleProduct","ParentGroupedProductId":0,"ManufacturerSizeId":2767,"VisibleIndividually":false,"Name":"Jako Ballenzak Kids - Ash / Action Green","ExtraName":null,"Description":"• Aangenaam functioneel materiaal\nmet moderne oppervlaktestructuur\nvoor de hoogste normen\n• Zeer goede klimaateigenschappen\ndoor actief ademend Twill-Polyester\n• Rekbaar, vormvast en sneldrogend\n\nPolyester-Twill\n100% Polyester,\nbinnenvoering: 100% Polyester","MetaTitle":null,"MetaDescription":null,"DisplayOrder":1,"LimitedToStores":false,"Sku":"9894","UniqueCode":"6_9","Price":34.96,"OldPrice":49.95,"SpecialPrice":null,"SpecialPriceStartDateTime":null,"SpecialPriceEndDateTime":null,"DiscountPercentage":0.00,"HasTierPrices":true,"HasStock":false,"TaxRate":"Tax_21","SyncToShop":true,"Deleted":false,"Locked":false,"State":"Changed","DateChanged":"2014-02-28T10:35:47.733","DateCreated":"2014-02-28T10:35:47.733","ProductCategories":[],"ProductManufacturers":[],"ProductPictures":[],"ProductSpecificationAttributes":[],"ProductStockItems":[]}]

元数据请求:

http://testdomain.local/breeze/DataContext/Metadata

错误客户端:(创建新的productStockItem)

Unable to locate a 'Type' by the name: 'ProductStockItem'. Be sure to execute a query or call fetchMetadata first.

    function createProductStockItem(initialValues) {
        return this.manager.createEntity("ProductStockItem", initialValues);
    }

1 个答案:

答案 0 :(得分:1)

重建应用程序时,元数据将会更新。没有额外的工作需要制作 要使用更新后的状态获取元数据。

每当您对元数据中包含的实体发出查询时,都会更新元数据 会被抓住。

对于创建实体,如果您直接导航到包含查询的任何页面之前创建实体的页面,则在这种情况下将不会获取元数据。

当您拨打fetchMetadata()时,仍然会收到错误消息:

Unable to locate a 'Type' by the name: 'New Class'. Be sure to execute a query or call `fetchMetadata` first

该消息并不表示已提取元数据。它仍然告诉您实体是未知的,并且仍未提取元数据。

为什么呢?因为在createEntity()之前调用了fetchMetadata()。 (你可以设置一个断点,看看它在行动中)

之前我碰到过这个,我做了什么,我只是将fetchMetadata()放在应用程序启动上。

这将保证在创建实体的任何调用之前首先获取它。

或者您可以使用承诺:

 manager.fetchMetadata().then(createProductStockItem("Initial values"));