1
votes

I have an Angular + Breeze + WebApi(EF) setup which works very well when querying for data. The breezeProvider is set for camelCase on the client by default, and PascalCase on the server side.

bp.NamingConvention.camelCase.setAsDefault();

The trouble I'm having is when pushing new data over signalR to my app. The data arrives PascalCased from the .NET Stack (Breeze explicity says to not mess with the casing on the server). I then use the standard factory to create a new entity and try to initialize it with the passed values. Since the initialier hash is all PascalCased, most of the properties fail to initialize properly. Is there a way to tell Breeze that it should convert this data the same way that it does when querying? I have not yet been successful. Basically, I just want Breeze to treat this the same as it treats all of the data it receives.

function onSignalRData(call){
    var callType = manager.metadataStore.getEntityType("Call");

    // call json from server is like { Id: 1, Name: "Paul", IsActive: true }
    // I think Breeze expects        { id: 1, name: "Paul", isActive: true }
    var newCall = callType.createEntity(call);
}

Any suggestions? I see Breeze mentions manually defined naming conventions, but again I'm not doing anything exotic here, just doing the same thing that Breeze does on queries but in a creation initializer.

1

1 Answers

0
votes

This may not be the best solution, but it seems to work for me. I used the same method as formatting json data to be camelCased and reparsed the data with a reviver function to camelCase it. I'm surprised that there's not a pipeline block in breeze entityManager.createEntity(...) that can handle this.

function reviver(key, val) {
    if (key)
        this[key.charAt(0).toLowerCase() + key.slice(1)] = val;
    else
        return val;
}

var parsed = JSON.parse(myjson, reviver);