2014-01-22 30 views
0

我有一種情況,我在單個SaveChanges期間保存多種類型的實體。在某些情況下,這種保存將包括我的「目標實體」,在某些情況下不包含。在保存包含「目標實體」的情況下,我需要能夠捕獲使用saveChanges()saveResult從服務器返回的實體ID。保存更改後找到特定實體的ID

我一直在試圖弄清楚如何使用Breeze EntityType來查看我的「目標實體」在saveResult中,但我一直在下面的方法中得到未定義。顯然,我不瞭解如何使用此功能?

function trapTargetEntityId(saveResult) { 
     saveResult.entities.forEach(function(entity) { 
      if (entity.EntityType === 'targetEntity') { 
       targetEntitId = entity.id; 
      } 
      return; 
     }); 
    } 

回答

0

不知道我明白。但如果你以後尋找一個特定的實體者皆保存

// make sure that targetType is NOT null 
var targetType = myEntityManager.metadataStore.getEntityType("Customer"); 
var targetId = 23452; // arbitrary id 

function trapTargetEntityId(saveResult) { 

    saveResult.entities.forEach(function(entity) { 
     // assumes that you have a data property called 'id' on the 'Customer' entityType 
     if (entity.entityType === targetType && entity.id === targetId) { 
      targetEntity = entity; 
      // do something with 'targetEntity' 
     } 

    }); 
} 

...,小心你的外殼 - 在你的榜樣應該是說「entity.entityType」而不是「entity.EntityType」

+0

玩過這一點之後,我發現我只需要從元數據存儲中獲取實體類型,並且實際上是回到這裏來回答我自己的問題。花了我一點時間,但是非常感謝你的迴應! – zpydee

相關問題