1

我唯一能找到的关于微风.js 中枚举支持的内容是关于 uservoice 的这个功能建议,最近在 0.82 中被标记为关闭。我正在使用当前最新的 0.84.3。

更新: 我首先在 EF 5.0.0 和 .net 4.5 中使用代码。启动应用程序和微风请求元数据时,EF 创建空数据库,我的枚举属性在数据库中为 int,所以这部分没问题。

但是,当我向模型中添加枚举属性时,当微风尝试解析元数据时出现异常:

Uncaught Error: Unable to locate an 'Type' by the name: ItemType:#TestApp.Models breeze.debug.js:5051
getTypeFromMap breeze.debug.js:5051
ctor.getEntityType breeze.debug.js:5028
ctor._updateProperty breeze.debug.js:6056
ctor._fixup breeze.debug.js:6133
ctor._fixup breeze.debug.js:6132
ctor.addEntityType breeze.debug.js:4702
convertFromODataEntityType

这是我的模型(简化):

public enum ItemType
  {
    Ordered,
    Approved,
    Misc
  }

public class Item 
  {

    public long Id { get; set; }

    public ItemType Type { get; set; }

  }

我在哪里犯错?是否有带枚举的工作样本?

4

1 回答 1

2

我刚刚尝试将您的 ItemType 枚举添加到我们的模型之一(微风 DocCode 示例中的 ToDo 模型)没有问题。

我不确定你遇到了什么。所以有两个建议,

1) 尝试更新(破解)微风示例 zip 中附带的 DocCode 示例以使用您的 ItemType 枚举(详情如下),然后运行任何基本的 ToDo 测试。

// In DocCode/Models/ToDoItem.cs
namespace Todo.Models 
{
    public class TodoItem 
    {
        public int Id { get; set; }                     // 42

        [Required, StringLength(maximumLength: 30)]     // Validation rules
        public string Description { get; set; }         // "Get milk"

        public System.DateTime CreatedAt { get; set; }  // 25 August 2012, 9am PST
        public bool IsDone { get; set; }                // false
        public bool IsArchived { get; set; }            // false
        // YOUR ENUM PROPERTY
        public ItemType Type { get; set; }
    }

    // YOUR ENUM TYPE
    public enum ItemType {
      Ordered,
      Approved,
      Misc
    }

}

// In DocCode/Models/ToDoDatabaseInitializer
private static TodoItem CreateTodo(string description, bool isDone, bool isArchived)
{
    _baseCreatedAtDate = _baseCreatedAtDate.AddMinutes(1);
    return new TodoItem
    {
        CreatedAt = _baseCreatedAtDate,
        Description = description,
        IsDone = isDone,
        IsArchived = isArchived,
        // YOUR ENUM PROPERTY
        Type = ItemType.Ordered
    };
}

或者

2) 向我 (Jay Traband) 发送您项目的精简版,地址为:brief@ideablade.com。

于 2013-01-14T19:18:00.653 回答