在模型上使用枚举属性时,客户端breeze.js中的异常 [英] Exception in client breeze.js when using enum property on model

查看:174
本文介绍了在模型上使用枚举属性时,客户端breeze.js中的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在breeze.js中我可以找到关于枚举支持的唯一的事情是此功能建议在uservoice上,最近被标记为0.82封闭。
我正在使用最新的0.84.3。



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



但是,当我添加我的模型的枚举属性,当微风试图解析元数据时,我有异常:

 未捕获错误:无法找到类型'名称: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 
{
已订购,
已批准,
Misc
}

public class Item
{

public long Id {get;组; }

public ItemType Type {get;组;

}

我在哪里犯错?有没有使用枚举的工作样本?

解决方案

我刚刚尝试将ItemType枚举添加到我们的一个模型中(ToDo模型在微风DocCode样本)没有问题。



我不知道你正在遇到什么。所以两个建议,



1)尝试更新(hack)在微风样本zip中发送的DocCode示例,以使用您的ItemType枚举(下面的详细信息),然后运行任何基本的ToDo测试。

  //在DocCode / Models / ToDoItem.cs 
命名空间Todo.Models
{
public class TodoItem
{
public int Id {get;组; } // 42

[必需,StringLength(maximumLength:30)] //验证规则
public string描述{get;组; } //Get milk

public System.DateTime CreatedAt {get;组; } // 2012年8月25日,上午9点PST
public bool IsDone {get;组; } // false
public bool IsArchived {get;组; } // false
//你的ENUM属性
public ItemType Type {get;组;
}

//您的ENUM类型
public枚举ItemType {
已订购,
已批准,
Misc
}

}

//在DocCode / Models / ToDoDatabaseInitializer
private static TodoItem CreateTodo(string description,bool isDone,bool isArchived)
{
_baseCreatedAtDate = _baseCreatedAtDate.AddMinutes(1);
返回新TodoItem
{
CreatedAt = _baseCreatedAtDate,
描述=描述,
IsDone = isDone,
IsArchived = isArchived,
//你的ENUM属性
Type = ItemType.Ordered
};
}



2)发送给我(Jay Traband)你的项目的一个被删除的版本在breeze@ideablade.com。


The only thing I could find about enum support in breeze.js is this feature suggestion on uservoice, which was recently marked as closed in 0.82. I'm using currently latest, 0.84.3.

UPDATE: I'm using code first in EF 5.0.0 with .net 4.5. When starting application and breeze makes request for metadata, EF creates empty database and my enum property is in database as int, so that part is ok.

However, when I added an enum property to my model, I got exception when breeze tried to parse metadata:

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

This is my model (simplified):

public enum ItemType
  {
    Ordered,
    Approved,
    Misc
  }

public class Item 
  {

    public long Id { get; set; }

    public ItemType Type { get; set; }

  }

Where am I making mistake? Is there working sample with enum?

解决方案

I just tried adding your ItemType enum to one of our models ( the ToDo model in the breeze DocCode sample) without a problem.

I am not sure what you are running into. So two suggestions,

1) Try updating (hack) the DocCode sample that ships within the breeze samples zip to use your ItemType enum ( details below) and then run any of the basic ToDo tests.

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

or

2) Send me (Jay Traband) a stripped down version of your project at breeze@ideablade.com.

这篇关于在模型上使用枚举属性时,客户端breeze.js中的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆