具有breeze和枚举值的createEntity

时间:2014-03-11 08:47:40

标签: entity-framework angularjs enums breeze

我创建了一个带角度和微风的应用程序,并在几乎所有类中都使用了一个Enum(State)属性。现在我想用微风创建一个实体,但在“State”属性上出错。有没有办法可以在我的整个角度/微风应用程序中使用Enum类型?我该如何处理/调用Enum类型?


 function createProductManufacturer(productId, manufacturerId) {
        return this.manager.createEntity(model.entityNames.productManufacturer,
            {
                ProductId: productId,
                ManufacturerId: manufacturerId,
                State: State.Changed // here is the problem...
            });
  }

public class ProductManufacturer
{        
    public int Id { get; set; }
    public int ProductId { get; set; }
    public int ManufacturerId { get; set; }
    public int DisplayOrder { get; set; }
    public State State { get; set; }

    public virtual Product Product { get; set; }
    public virtual Manufacturer Manufacturer { get; set; }
}


public enum State
{
    Normal = 0,
    Changed = 1,
    Deleted = 2
}

1 个答案:

答案 0 :(得分:1)

到目前为止,您所做的只会显示一个Enum State名称,该名称与一个实体ProductManufacturer相对应。即,在针对ProductManufacturer执行实体查询时,您将获得每个ProductManufacturer实体,并附带一个State名称。

如果要发送enum state值,则需要将它们公开为查找对象。

BreezeController,添加HTTPGET方法并添加enum值:

    [HttpGet]
    public object Lookups()
    {
        var  States = Enum.GetNames(typeof(State));// This is how you expose Enum values 
        var  Countries = _contextProvider.Context.Countries; // This one is a database lookup table
       return new {States, Countries  };
     }

然后,您可以使用典型的微风EntityQuery查询您的查找(在应用程序启动时执行此操作。)

相关问题