Include server side properties not mapped to entity framework entity
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 }
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
This sounds like something that Ward Bell mentioned - maybe the property has a null value and by default Breeze does not return it.
Check out adding a custom breeze configuration class as mentioned here to tweak the way null values are returned in the Json. Just adding this class into your Web Api project means Breeze will look for it automatically and configure this.
http://www.breezejs.com/documentation/web-api-controller
链接地址: http://www.djcxy.com/p/72962.html上一篇: jQuery AJAX或XHR请求触发器未能完成回调的回调
下一篇: 包括未映射到实体框架实体的服务器端属性