UnMapped property on the Angular/Breeze SPA template

后端 未结 3 1119
逝去的感伤
逝去的感伤 2020-12-20 09:47

I am using the Angular/Breeze SPA template in visual studio 2012. I have added an unmapped property in the TodoList server model.

[NotMapped]
public string M         


        
3条回答
  •  一整个雨季
    2020-12-20 10:16

    Did you find a solution to this problem? I have been struggling with the same problem and just recently found this SO post by CassidyK, in which he solves a very similar problem by changing a single line in the Breeze source code (breeze.debug.js). Here is the code snippet he changed (taken from CassidyK's post):

    proto.initializeFrom = function (rawEntity) {
        // HACK:
        // copy unmapped properties from newly created client entity to the rawEntity.
        // This is so that we don't lose them when we update from the rawEntity to the target.
        // Something that will occur immediately after this method completes. 
        var that = this;
        this.entityType.unmappedProperties.forEach(function(prop) {
            var propName = prop.name;
            that[propName] = rawEntity[propName];  // CassidyK 
            //rawEntity[propName] = that[propName]; // Breeze 
        });
    
        if (!this._backingStore) {
            this._backingStore = { };
        }
    };
    

    I have tried this solution and it seems to work just fine. Notice that this change will probably get you into trouble if you ever have a case in which you have a server side property that's not mapped in the database, and need the client side to overwrite this value when the object is created at the client side.

提交回复
热议问题