Jeremy Danyow
Jeremy Danyow

Reputation: 26406

breezejs + entity framework: how to round-trip ad-hoc properties

I'm using breezejs with an entity framework 5 model. The model is the old-school edmx/objectcontext style- not the newer dbcontext/poco style.

The model is shared with some wcf ria services domain services so I cannot switch to entity framework 6 or poco style entity framework at this time.

When using wcf ria services, if you wanted to add a property to an entity beyond what is generated by entity framework you could create a partial class, define the property and annotate it with the datamember attribute. Wcf ria services treats this new property like any other property and sends it to the client from the server and back to the server.

Is there a way to do the same thing with breezejs? Without moving entirely away from the automatic metadata generation goodness that comes with using entity framework?

Using fiddler I can see the property I want exposed is transmitted to the client during a query request.

I've looked at the documentation here http://www.breezejs.com/documentation/extending-entities but none of the examples seem to fit this scenario.

Upvotes: 1

Views: 253

Answers (1)

Jay Traband
Jay Traband

Reputation: 17052

Breeze supports unmapped properties, these are properties that are declared on your javascript constructor that cannot be matched to any property in metadata. By default these properties are both persisted locally and sent to the server on a save. This is described in the link you mentioned: http://www.breezejs.com/documentation/extending-entities

 var Customer = function () {
     this.myUnmappedProperty = "anything22";
 };
 myEntityManager.metadataStore.registerEntityTypeCtor("Customer", Customer);

These values will be available on the server after a SaveChanges call via the 'UnmappedValuesMap' property on each EntityInfo instance.

 var unmappedValue = entityInfo.UnmappedValuesMap["myUnmappedProperty"];

What is sounds like you are looking for is "unmapped" properties to go in the "other" direction, i.e. from the server to the client. What might work for that but we haven't tried is adding a property to your server side EF class ( via the partial class mechanism) and mark it up for Json serialization. It "should" then get serialized down to the client, even though it won't show up in Metadata.

If this does NOT work, please post back here and we will consider it as a breeze feature request. The basic idea does make a lot of sense and we should support it.

Upvotes: 2

Related Questions