问题
I extended my server entity with some properties in the client side . When getting data from the query I really see these properties in the result filled with the proper values . When I change a value of an extended properties the manager doesn't track this change . When I call manager.rejectChanges() no action is happen , I debugged the code and I see in the entityAspect.entityState ("Unchaged") although I modified the property. If I modify a property comes from the server entity every thing is ok.
Here is my Product entity in the server :
public class Product
{
public string Code {get;set;}
}
I extended the product in the client side with some others :
var Product = function () {
this.kind = ko.observable();
};
breeze.metadataStore.registerEntityTypeCtor("Product", Product);
After the query I get both field (Code , Kind) , if I change Code , entity state is modified , I can call manager.rejectChanges and its takes effect, but if I change kind nothing happen , the entity state is "Unchaged". Any idea why this happen ? Thanks in advance ...
回答1:
By "extended" I assume you mean "unmapped" properties which are typically defined in a custom constructor as described in "Extending Entities"
"Unmapped" properties do not map to permanently stored values on the server. Therefore, changes to unmapped properties do not affect EntityState
and they are not sent to the server.
Note that the server can supply the value of an unmapped property in the payload of a query and Breeze will set the unmapped property accordingly. This is a way to calculate non-persisted values on the server and transmit them to the entity on the client.
On the client an unmapped property behaves in other respects like a mapped property:
- conforms to the syntax of the model library (e.g., it becomes an observable in KO models)
- serialized when exported
- validation rules apply
- raises
propertyChange
when the value is changed - entity remembers the property's "original value"
rejectChanges()
reverts the property to that original value
来源:https://stackoverflow.com/questions/20595438/breezemanager-doesnt-track-changes-with-extended-properties