这个[propertyName]不是breeze.debug.js中的函数

时间:2013-05-30 18:21:12

标签: asp.net-mvc-4 breeze hottowel

我正在使用热毛巾模板和使用微风的扩展功能。我已经使用breeze.partial-entities.js文件将breeze实体转换为可以由knockout observables使用的正确dtos,如下所示。

function dtoToEntityMapper(dto) {
            var keyValue = dto[keyName];
            var entity = manager.getEntityByKey(entityName, keyValue);
            if (!entity) {
                // We don't have it, so create it as a partial
                extendWith = $.extend({ }, extendWith || defaultExtension);
                extendWith[keyName] = keyValue;
                entity = manager.createEntity(entityName, extendWith);
            }
            mapToEntity(entity, dto);
            entity.entityAspect.setUnchanged();
            return entity;
        }

对于少数实体来说,它正常工作并将breeze数据转换为实体,但其中一个实体实现失败。其模型如下:

public class StandardResourceProperty
{
    [Key]
    public int Id { get; set; }
    public string Name { get; set; }
    public int StandardResourceId{ get; set; }
    public int InputTypeId{ get; set; }
    public int ListGroupId{ get; set; }
    public string Format{ get; set; }
    public string Calculation{ get; set; }
    public bool Required{ get; set; }
    public int MinSize{ get; set; }
    public int MaxSize{ get; set; }
    public string DefaultValue{ get; set; }
    public string Comment { get; set; }

    public virtual StandardResource AssociatedStandardResource { get; set; }
    public virtual List AssociatedList { get; set; }
}

我得到的错误是 TypeError:此[propertyName]不是函数 [打破此错误]

thispropertyName;

breeze.debug.js(第13157行)

代码

proto.setProperty = function(propertyName, value) {
        this[propertyName](value);
        // allow set property chaining.
        return this;
    };

请告诉我。实施中可能出现的问题也是如此,如果我能就如何调试和跟踪此类问题得到更多建议,那就太棒了。

1 个答案:

答案 0 :(得分:2)

让我们回来吧。我不明白你的意思是“将breeze实体转换为可以由knockout observables使用的正确dtos ”。 Breeze实体已配置为KO observables (假设您使用的是默认的Breeze模型库配置)。你想做什么?

我怀疑您正在关注Code Camper Jumpstart课程,它会进行getSessionPartials投影查询。该查询(与所有投影一样)返回DTO - 而不是实体 - 并使用dtoToEntityMapper方法将它们映射到Session个实体。

CCJS dtoToEntityMapper方法不能与实体一起使用。它用于从DTO转换为实体,并将DTO - 非实体 - 作为输入。

再见dtoEntityMapper

dtoToEntityMapper方法通过将.toType('StandardResourceProperty')添加到投影查询中来预先确定Breeze自动执行投影到实体映射的能力。

以下是CCJS getSessionPartials查询现在的样子:

var query = EntityQuery
    .from('Sessions')
    .select('id, title, code, speakerId, trackId, timeSlotId, roomId, level, tags')
    .orderBy(orderBy.session)
    .toType('Session');

如果你这样做,一定要在自定义构造函数中将isPartial标志的默认状态设置为true(参见 model.js

metadataStore.registerEntityTypeCtor(
    'Session', function () { this.isPartial = true; }, sessionInitializer);

注意 this.isPartial = true是CCJS示例的反向,默认值为 false

确保在查询或创建完整实体时设置isPartial(false)。在CCJS中,有两个地方可以做到这一点:成功回调getSessionByIdcreateSession中的{{1}}将成为:

var createSession = function () {
    return manager.createEntity(entityNames.session, {isPartial: false});
};