Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include server side properties not mapped to entity framework entity

Tags:

breeze

We are adding additional properties to our objects on the server that we do not track in the database. The data gets returned to the client but the object materialized by breeze does not have it as a property. How can we add properties to our objects that we return to breeze but not map them into the database where we store the data?

Example: Widget Class Property A - Mapped to Database Property B - Has [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 }

like image 872
StewartArmbrecht Avatar asked Jul 23 '13 18:07

StewartArmbrecht


1 Answers

Properties with NotMapped attributes are not part of the MetaData generated by EFContextProvider, so those properties won't be available in the client side breeze entity. But in js you can extend the client side entity and add the property to the entityType yourself (with an initial value set). This will make sure that the value for the property is correctly set when the json object is retrieved from the server.

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

like image 177
arul Avatar answered Oct 01 '22 17:10

arul