0

There are some posts about this, but nothing specific that works in my project.

I read the docs on Breeze about Extending Entities, but they use knockout and I am using Angular.

I have defined a custom property on the server and it is being passed down in my JSON.

However, Breeze js ingnores it because there is no meta data for it.

I need to define the meta data on the client so that Breeze can read the property.

Here is what I have the client so far, but it does not work. By not working... I mean when I call it with {{item.MyProp}} nothing ever shows up on the screen. However, all the other properties from the actual meta data show up just fine.

    configureBreeze();

var serviceName = 'api/Entity';

var manager = new breeze.EntityManager(serviceName);
manager.enableSaveQueuing(true);


var store = manager.metadataStore;

addMyPropType(store);

function addMyPropType(store) {
    store.registerEntityTypeCtor("Merchant", MyProp);
}

// custom Merchant constructor
var MyProp= function () {
    //'MyProp' is a server-side calculated property of the Merchant class
    // This unmapped property will be empty for new entities
    // but will be set for existing entities during query materialization
   this.MyProp= "test";
};

var dataservice = {
    store: store,
    List: List,
    Create: Create,
    ListDetail: ListDetail,
    Save: Save
};
return dataservice;

I have ready the NODB sample, but I do have a DB and it also uses KO.

UPDATE:

Ok. So I found something that partially works. The default value is now getting displayed on the view. However, the value from the JSON is not being filled in. It always uses the default value.

This is what I have now:

var Merchant = function () {
    this.MyProp = "5";
};
store.registerEntityTypeCtor("Merchant", Merchant);

What needs to happen for MyProp to be filled by the actual value from the JSON?

user2341148
  • 121
  • 2
  • 11

2 Answers2

0

If camelCasing is not your case as PWKad suggested then check breeze documentation for the Breeze Angular SPA template here http://www.breezejs.com/samples/breezeangular-template . There is a section in that link called "Extending entity definitions on the client" .

If I understand correctly you have a "Merchant" object with a "MyProp" calculated property. Try this

store.registerEntityTypeCtor("Merchant",Merchant, merchantInitializer);

function Merchant(){
 this.MyProp="";
}
  • I am actually using that template already, but it doesn't address this issue. I've read those docs also, but they use ko.observable which seems to be specific to Knockout. merchantInitializer would need to be a function and I'm not sure what that would have in it. I've tried a million combinations similar to what you posted. The problem is there is no error messages... it just doesn't work. I'm looking for a sample where someone got this working using Angular. I just need to define one property that is in my JSON, but not the meta data. – user2341148 Sep 22 '13 at 13:35
0

Well, it seems this is a bug in Breeze. You actually have to edit the breeze.js file to get it working. I never would have thought it was a bug.

I found the answer here:

Breeze Extended Entity Property Only Loads on Second Query

UPDATE:

Today I updated to the latest version of breeze.js and the bug does not exist anymore. So this was basically a lot of pain for no reason. Thanks everyone for the help. If you cannot update for some reason use the link above.

Community
  • 1
  • 1
user2341148
  • 121
  • 2
  • 11