【问题标题】:BreezeJs: Update to new metadata from changed BreezeControllerBreezeJs:从更改的 BreezeController 更新到新的元数据
【发布时间】:2014-03-14 05:08:08
【问题描述】:

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

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

更新(更多信息)


我创建了一个与我的 Product 类相关的子类。它叫做 ProductStockItem,所以一个 Product 有很多 ProductStockItem。

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);
    }

【问题讨论】:

  • Breeze 从实体框架中获取元数据。 Entity Framework 是否知道您的新属性和实体?
  • 是的。我已经重建了一切。当我手动调用元数据时,我会看到新的和更改的属性。
  • 您能否提供更多信息,例如您添加了新属性的类以及客户端代码。?从错误中; 'New Class' 是实体类吗?
  • 我添加了更多信息
  • 我更改了数据库中的一些值,并从一个类中删除了一些属性,但微风一直告诉我必须为那个“已删除”的属性设置一个值?我使用包管理器控制台 - update-database -verbose - (Code First) 方法。

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


【解决方案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"));

【讨论】:

    猜你喜欢
    • 2013-05-16
    • 2011-11-28
    • 2012-02-23
    • 2021-08-14
    • 2013-01-19
    • 2020-05-18
    • 2011-08-13
    • 1970-01-01
    • 2019-03-30
    相关资源
    最近更新 更多