1

我已經更改並向服務器端類添加了一些屬性,但無法在我的微風/角度應用程序中獲取更新的數據。添加的字段保持空白而不顯示值。我也無法創建我添加的實體。 (錯誤)。如何在我的微風/角度應用程序中更新元數據以使用最新版本?我試圖獲取元數據,但獲取已獲取的消息。BreezeJs:從已更改的BreezeController更新到新的元數據

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

更新(詳細信息)


我創建我的相關產品類的子類。它被稱爲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); 
    } 
+0

微風從實體框架獲取元數據。實體框架是否知道你的新屬性和實體? –

+0

是的。我已經重建了一切。當我手動調用元數據時,我會看到新的和已更改的屬性。 – Nesse

+0

您是否會提供更多信息,例如您添加了新屬性的類以及客戶端代碼。從錯誤; '新班'是一個實體班? –

回答

1

當你重建你的應用程序中,元數據將得到更新。不需要額外的工作就可以使 元數據獲取更新後的狀態。

只要您對元數據中包含的實體發出查詢,就會獲取更新後的元數據 。

對於創建實體,如果直接導航到在包含查詢的任何頁面之前創建實體的頁面,則在這種情況下不會獲取元數據。

當你叫fetchMetadata(),你仍然得到錯誤:

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

該消息並不表示該元數據已經是牽強。它仍然告訴你實體是未知的,元數據仍然沒有被提取。

爲什麼?因爲在fetchMetadata()之前調用createEntity()。 (你可以設置一個斷點,並看到在行動)

我碰到過,我做了什麼,我只是把fetchMetadata()在應用程序啓動。

這將保證它會在任何調用創建實體之前獲取。

或者你可以只使用一個承諾:

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