The extended Breeze Entity property is only loaded on the second request.

Hope someone has a better idea of ​​the Breeze Extended elements, because I'm at a dead end! So, I created a partial class (WO_Rout) on the server side (web API using the Breeze API) and created a property called "AssetJobEqNo".

I read and followed the Breeze document here to no avail. Following the tutorial, I created a constructor for this particular WO_Rout object as follows:

var assets = function () { this.AssetJobEqNo = ''; }; var serviceName = 'cms8/workorders'; var manager = new breeze.EntityManager({ serviceName: serviceName }); var store = manager.metadataStore; store.registerEntityTypeCtor('WO_Rout', assets); 

When I request my controller, this specific “AssetJobEqNo” property is sent and displayed in the client side JSON source results.

So ... here is the weird part that I cannot understand. If I run a request bound to a button on my user interface, then the IS property is loaded, and in the object that I assigned to it, BUT this is still the default value of the empty line, it never loads. Then I run the EXACT same query again, capturing the same objects again, and this time the IS value is there.

In conclusion, I am confused why this extended property of the object is not populated with the first request, but if I run the same request that it loads a second time?

Hope this all makes sense.

dataService function:

 function getWorkOrder(reqNo) { if (reqNo > 0) { var query = breeze.EntityQuery.from("GetWorkOrders"); query = query.where("req_no", "==", reqNo) .expand(["WO_RtHelp.WO_Rout", "WO_RtHelp.WO_Rout.eqptmast", "WO_RtHelp.WO_Act.WO_Resources.persmast", "WO_RtHelp.WO_Act.WO_Resources.Kits", "WO_RtHelp.WO_Act.Activity", "WO_RtHelp.WO_Act.WO_Resources.customer", "WO_RtHelp.WO_Act.WO_Resources.eqptmast", "WO_RtHelp.WO_Act.WO_Resources.invsite.invmast", "WO_RtHelp.WO_Act.WO_Resources.crew"]) return manager.executeQuery(query); } else { return throwNotification('Please enter a Work Order number.'); } } 

controller function for subsequent requests

 function querySucceeded(data) { $scope.WorkOrder = {}; if (data.results.length === 0) { sysErrorNotification('No Work Order with System #' + $scope.workOrderSearchNumber); } else { $scope.WorkOrder = data.results[0]; $scope.myData = $scope.WorkOrder.WO_RtHelp; $('#bottomNav a[href="/WorkOrders/#woMain"]').tab('show'); resetDataSources(); $scope.$apply(); } } 

I use Breeze, Angular, Q and jQuery

+1
source share
2 answers

So, after several days of beating, I believe that I solved the problem. After the entity created and combined the process in it, when materializing from the request, I found that my property was overwritten with "rawEntity", which has a default value from the extended property of the object "".

I am using Breeze 1.4.2 and debugging with breeze.debug.js and found proto.initializeFrom function on line 14854 causing this problem.

Here is what I did to fix this problem:

  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 will keep this update if I find any problems with the fix I implemented here.

+1
source

Pay attention to Ward's answer in the next question - he should give you guidance on unlabeled properties.

UnMapped property in Angular / Breeze SPA template

I don’t see how it works at all, to be honest, if I don’t miss something that you killed expand ()

 query = query.where("req_no", "==", reqNo) .expand(["WO_RtHelp.WO_Rout", "WO_RtHelp.WO_Rout.eqptmast", "WO_RtHelp.WO_Act.WO_Resources.persmast", "WO_RtHelp.WO_Act.WO_Resources.Kits", "WO_RtHelp.WO_Act.Activity", "WO_RtHelp.WO_Act.WO_Resources.customer", "WO_RtHelp.WO_Act.WO_Resources.eqptmast", "WO_RtHelp.WO_Act.WO_Resources.invsite.invmast", "WO_RtHelp.WO_Act.WO_Resources.crew"]) 

should be a string, with values ​​shared inside it -

  query = query.where("req_no", "==", reqNo) .expand("WO_RtHelp.WO_Rout", "WO_RtHelp.WO_Rout.eqptmast, WO_RtHelp.WO_Act.WO_Resources.persmast, WO_RtHelp.WO_Act.WO_Resources.Kits, WO_RtHelp.WO_Act.Activity, WO_RtHelp.WO_Act.WO_Resources.customer, WO_RtHelp.WO_Act.WO_Resources.eqptmast, WO_RtHelp.WO_Act.WO_Resources.invsite.invmast, WO_RtHelp.WO_Act.WO_Resources.crew") 

Please note that I did not pass an array of strings, I passed a string that separated values ​​with commas.

0
source

Source: https://habr.com/ru/post/973581/


All Articles