Enable server-side properties that are not tied to an entity infrastructure object

We add additional properties to our objects on the server, which we do not track in the database. Data is returned to the client, but an object materialized by the wind does not have it as a property. How can we add properties to our objects, which we return to the wind, but do not map them to the database where we store the data?

Example: widget class Property A - mapped to the database Property B - has the [NotMapped] attribute so that it is not stored in the database. It is calculated on the fly by the server.

When we get the object on the client, we get: Widget class = {Property A: ko.observable (value for A)}

Property B is missing.

When we look at the json returned by the server, we see:

Widget class = {Property A: Value for A, Property B: Value for B}

+7
breeze
source share
2 answers

Properties with NotMapped attributes are not part of the MetaData generated by EFContextProvider, so these properties will not be available in branches on the client side. But in js, you can extend the client-side object and add the property to entityType yourself (with the initial value set). This will ensure that the property value is set correctly when the json object is retrieved from the server.

http://www.breezejs.com/documentation/extending-entities

+4
source share

This is similar to what Ward Bell mentioned, the property may have a value of zero, and Breeze will not return it by default.

Check out the addition of the custom breeze configuration class as outlined here to set up a way to return null values ​​in Json. Just adding this class to your Web Api project means that Breeze will automatically search for it and configure it.

http://www.breezejs.com/documentation/web-api-controller

0
source share

All Articles