0
votes

I am using Hot towel template and extended functionality of it by using breeze. I have used breeze.partial-entities.js file to conver breeze entities to proper dtos that can be used by knockout observables as shown below.

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

For few of the entities it is working properly and getting breeze data converted to entities but for one of the entity implementation is failing. Model for the same is given as below.

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

The error i am getting is TypeError: this[propertyName] is not a function [Break On This Error]

thispropertyName;

breeze.debug.js (line 13157)

]

with code

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

Please let me know . What can be possible issue with the implementation also , it would be great if i can get more suggestion on how to debug and trace such issues.

1

1 Answers

2
votes

Let's back up. I do not understand what you mean by "convert breeze entities to proper dtos that can be used by knockout observables". Breeze entities are already configured as KO observables (assuming you are using the default Breeze model library configuration). What are you trying to do?

I suspect you are following along with the Code Camper Jumpstart course where it does a getSessionPartials projection query. That query (like all projections) returns DTOs - not entities - and maps them with the dtoToEntityMapper method into Session entities.

The CCJS dtoToEntityMapper method cannot be used with entities. It is for converting from a DTO to an Entity and takes DTOs - not entities - as input.

Goodbye to dtoEntityMapper

The dtoToEntityMapper method pre-dates the ability of Breeze to automate projection-to-entity mapping by adding .toType('StandardResourceProperty') to your projection query.

Here is what the CCJS getSessionPartials query could look like now:

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

If you go this way, be sure to set the default state of the isPartial flag to true in the custom constructor (see model.js)

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

Note that this.isPartial = true is the reverse of the CCJS example where the default was false.

Make sure that you set isPartial(false) when you query or create a full entity. In CCJS there are two places to do that: in the success-callback of getSessionById AND in createSession which would become:

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