Asp.net mvc 4 此[propertyName]不是breeze.debug.js中的函数

Asp.net mvc 4 此[propertyName]不是breeze.debug.js中的函数,asp.net-mvc-4,breeze,hottowel,Asp.net Mvc 4,Breeze,Hottowel,我正在使用热毛巾模板和它的扩展功能,使用微风。我已经使用breeze.partial-entities.js文件将breeze实体转换为合适的DTO,这些DTO可以被敲除观测值使用,如下所示 function dtoToEntityMapper(dto) { var keyValue = dto[keyName]; var entity = manager.getEntityByKey(entityName, keyValue);

我正在使用热毛巾模板和它的扩展功能,使用微风。我已经使用breeze.partial-entities.js文件将breeze实体转换为合适的DTO,这些DTO可以被敲除观测值使用,如下所示

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]不是函数 [在此错误上中断]

此属性名称

breeze.debug.js(第13157行)

]

带代码

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

请让我知道。实现中可能出现的问题还有,如果我能得到更多关于如何调试和跟踪这些问题的建议,那就太好了。

让我们备份一下。我不明白你所说的“将breeze实体转换为可以被淘汰的可观测对象使用的适当DTO”是什么意思微风实体已配置为KO可观测对象(假设您使用的是默认微风模型库配置)。你想干什么

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

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

再见dtoEntityMapper
dtototentitymapper
方法通过将
.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'); 注意
this.isPartial=true
是默认值为false的CCJS示例的反面

查询或创建完整实体时,请确保设置了
isPartial(false)
。在CCJS中有两个地方可以这样做:在
getSessionById
的成功回调中,以及在
createSession
中,这将成为:

var createSession = function () { return manager.createEntity(entityNames.session, {isPartial: false}); }; var createSession=函数(){ return manager.createEntity(entityNames.session,{isPartial:false}); };
这引发了另一个问题。首次加载数据时,所有实体都具有
isparial==true
(来自ctor)。然后,如果我们选择加载一个实体的所有数据(我们称之为
e
),我们将其设置为
e.isPartial(false)
。如果我们随后重新加载(即使用
forceRemote
调用
getSessionPartials
以设置
true
),则
e
的数据将被删除,部分数据将从服务器中提取并分配给
e
,但
e.isPartial
仍然为false。因此,如果我们现在再次尝试按id加载
e
的数据,应用程序会发现
e
是部分的,不会刷新它。我最终在本地查询了所有实体,然后将它们分离,然后再进行重新查询。这聪明吗? var createSession = function () { return manager.createEntity(entityNames.session, {isPartial: false}); };