我已经更改并添加了一些属性到我的服务器端类,但无法在我的breeze/angular应用程序中获得更新的数据。添加的字段保持空白而不是显示值。我也不能创建我添加的实体。(错误)。我如何更新元数据在我的微风/角应用程序使用最新版本?我试图获取元数据,但得到的消息是它已经被获取。
Breeze: Unable to locate a 'Type' by the name: 'New Class'. Be sure to execute a query or call fetchMetadata first
Update (More Info)
我已经创建了一个与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 materiaalnmet moderne oppervlaktestructuurnvoor de hoogste normenn• Zeer goede klimaateigenschappenndoor actief ademend Twill-Polyestern• Rekbaar, vormvast en sneldrogendnnPolyester-Twilln100% 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
客户端错误:(create new 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);
}
在重新构建应用程序时,元数据将得到更新。不需要额外的工作来制作
元数据的更新状态当您对包含在元数据中的实体发出查询时,更新的元数据
对于创建实体,如果在包含查询的任何页面之前直接导航到创建实体的页面,则在这种情况下不会获取元数据。
当你调用fetchMetadata()
时,你仍然得到错误:
Unable to locate a 'Type' by the name: 'New Class'. Be sure to execute a query or call `fetchMetadata` first
该消息不表示已获取元数据。它仍然告诉你实体是未知的,元数据仍然没有被获取。
为什么?因为createEntity()
在fetchMetadata()
之前。(你可以设置一个断点,看看它是如何工作的)
我以前遇到过这个问题,我所做的是,我只是把fetchMetadata()
放在应用程序启动上。
这将保证在任何创建实体的调用之前,它将首先被获取。
或者你可以直接使用promise:
manager.fetchMetadata().then(createProductStockItem("Initial values"));