build/breeze.debug.js
function mergeEntity(mc, node, meta) {
    node._$meta = meta;
    var em = mc.entityManager;

    var entityType = meta.entityType;
    if (typeof (entityType) === 'string') {
      entityType = mc.metadataStore._getEntityType(entityType, false);
    }
    node.entityType = entityType;

    var mergeStrategy = mc.mergeOptions.mergeStrategy;
    var isSaving = mc.query == null;

    var entityKey = entityType.getEntityKeyFromRawEntity(node, mc.rawValueFn);
    var targetEntity = em.findEntityByKey(entityKey);
    if (targetEntity) {
      if (isSaving && targetEntity.entityAspect.entityState.isDeleted()) {
        em.detachEntity(targetEntity);
        return targetEntity;
      }
      var targetEntityState = targetEntity.entityAspect.entityState;
      if (mergeStrategy === MergeStrategy.Disallowed) {
        throw new Error("A MergeStrategy of 'Disallowed' prevents " + entityKey.toString() + " from being merged");
      } else if (mergeStrategy === MergeStrategy.SkipMerge) {
        updateEntityNoMerge(mc, targetEntity, node);
      } else {
        if (mergeStrategy === MergeStrategy.OverwriteChanges
            || targetEntityState.isUnchanged()) {
          updateEntity(mc, targetEntity, node);
          targetEntity.entityAspect.wasLoaded = true;
          if (meta.extraMetadata) {
            targetEntity.entityAspect.extraMetadata = meta.extraMetadata;
          }
          targetEntity.entityAspect.entityState = EntityState.Unchanged;
          clearOriginalValues(targetEntity);
          targetEntity.entityAspect.propertyChanged.publish({ entity: targetEntity, propertyName: null });
          var action = isSaving ? EntityAction.MergeOnSave : EntityAction.MergeOnQuery;
          em.entityChanged.publish({ entityAction: action, entity: targetEntity });
          // this is needed to handle an overwrite of a modified entity with an unchanged entity
          // which might in turn cause _hasChanges to change.
          if (!targetEntityState.isUnchanged()) {
            em._notifyStateChange(targetEntity, false);
          }
        } else {
          if (targetEntityState == EntityState.Deleted && !mc.mergeOptions.includeDeleted) {
            return null;
          }
          updateEntityNoMerge(mc, targetEntity, node);
        }
      }
    } else {
      targetEntity = entityType._createInstanceCore();

      updateEntity(mc, targetEntity, node);

      if (meta.extraMetadata) {
        targetEntity.entityAspect.extraMetadata = meta.extraMetadata;
      }
      // em._attachEntityCore(targetEntity, EntityState.Unchanged, MergeStrategy.Disallowed);
      em._attachEntityCore(targetEntity, EntityState.Unchanged, mergeStrategy);
      targetEntity.entityAspect.wasLoaded = true;
      em.entityChanged.publish({ entityAction: EntityAction.AttachOnQuery, entity: targetEntity });
    }
    return targetEntity;
  }
function mergeEntity(mc, node, meta) {
    node._$meta = meta;
    var em = mc.entityManager;

    var entityType = meta.entityType;
    if (typeof (entityType) === 'string') {
      entityType = mc.metadataStore._getEntityType(entityType, false);
    }
    node.entityType = entityType;

    var mergeStrategy = mc.mergeOptions.mergeStrategy;
    var isSaving = mc.query == null;

    var entityKey = entityType.getEntityKeyFromRawEntity(node, mc.rawValueFn);
    var targetEntity = em.findEntityByKey(entityKey);
    if (targetEntity) {
      if (isSaving && targetEntity.entityAspect.entityState.isDeleted()) {
        em.detachEntity(targetEntity);
        return targetEntity;
      }
      var targetEntityState = targetEntity.entityAspect.entityState;
      if (mergeStrategy === MergeStrategy.Disallowed) {
        throw new Error("A MergeStrategy of 'Disallowed' prevents " + entityKey.toString() + " from being merged");
      } else if (mergeStrategy === MergeStrategy.SkipMerge) {
        updateEntityNoMerge(mc, targetEntity, node);
      } else {
        if (mergeStrategy === MergeStrategy.OverwriteChanges
            || targetEntityState.isUnchanged()) {
          updateEntity(mc, targetEntity, node);
          targetEntity.entityAspect.wasLoaded = true;
          if (meta.extraMetadata) {
            targetEntity.entityAspect.extraMetadata = meta.extraMetadata;
          }
          targetEntity.entityAspect.entityState = EntityState.Unchanged;
          clearOriginalValues(targetEntity);
          targetEntity.entityAspect.propertyChanged.publish({ entity: targetEntity, propertyName: null });
          var action = isSaving ? EntityAction.MergeOnSave : EntityAction.MergeOnQuery;
          em.entityChanged.publish({ entityAction: action, entity: targetEntity });
          // this is needed to handle an overwrite of a modified entity with an unchanged entity
          // which might in turn cause _hasChanges to change.
          if (!targetEntityState.isUnchanged()) {
            em._notifyStateChange(targetEntity, false);
          }
        } else {
          if (targetEntityState == EntityState.Deleted && !mc.mergeOptions.includeDeleted) {
            return null;
          }
          updateEntityNoMerge(mc, targetEntity, node);
        }
      }
    } else {
      targetEntity = entityType._createInstanceCore();

      updateEntity(mc, targetEntity, node);

      if (meta.extraMetadata) {
        targetEntity.entityAspect.extraMetadata = meta.extraMetadata;
      }
      // em._attachEntityCore(targetEntity, EntityState.Unchanged, MergeStrategy.Disallowed);
      em._attachEntityCore(targetEntity, EntityState.Unchanged, mergeStrategy);
      targetEntity.entityAspect.wasLoaded = true;
      em.entityChanged.publish({ entityAction: EntityAction.AttachOnQuery, entity: targetEntity });
    }
    return targetEntity;
  }
function mergeEntity ( mc , node , meta ) { node . _$meta = meta ; var em = mc . entityManager ; var entityType = meta . entityType ; if ( typeof ( entityType ) === 'string' ) { entityType = mc . metadataStore . _getEntityType ( entityType , false ) ; } node . entityType = entityType ; var mergeStrategy = mc . mergeOptions . mergeStrategy ; var isSaving = mc . query == null ; var entityKey = entityType . getEntityKeyFromRawEntity ( node , mc . rawValueFn ) ; var targetEntity = em . findEntityByKey ( entityKey ) ; if ( targetEntity ) { if ( isSaving && targetEntity . entityAspect . entityState . isDeleted ( ) ) { em . detachEntity ( targetEntity ) ; return targetEntity ; } var targetEntityState = targetEntity . entityAspect . entityState ; if ( mergeStrategy === MergeStrategy . Disallowed ) { throw new Error ( "A MergeStrategy of 'Disallowed' prevents " + entityKey . toString ( ) + " from being merged" ) ; } else if ( mergeStrategy === MergeStrategy . SkipMerge ) { updateEntityNoMerge ( mc , targetEntity , node ) ; } else { if ( mergeStrategy === MergeStrategy . OverwriteChanges || targetEntityState . isUnchanged ( ) ) { updateEntity ( mc , targetEntity , node ) ; targetEntity . entityAspect . wasLoaded = true ; if ( meta . extraMetadata ) { targetEntity . entityAspect . extraMetadata = meta . extraMetadata ; } targetEntity . entityAspect . entityState = EntityState . Unchanged ; clearOriginalValues ( targetEntity ) ; targetEntity . entityAspect . propertyChanged . publish ( { entity : targetEntity , propertyName : null } ) ; var action = isSaving ? EntityAction . MergeOnSave : EntityAction . MergeOnQuery ; em . entityChanged . publish ( { entityAction : action , entity : targetEntity } ) ; // this is needed to handle an overwrite of a modified entity with an unchanged entity // which might in turn cause _hasChanges to change. if ( ! targetEntityState . isUnchanged ( ) ) { em . _notifyStateChange ( targetEntity , false ) ; } } else { if ( targetEntityState == EntityState . Deleted && ! mc . mergeOptions . includeDeleted ) { return null ; } updateEntityNoMerge ( mc , targetEntity , node ) ; } } } else { targetEntity = entityType . _createInstanceCore ( ) ; updateEntity ( mc , targetEntity , node ) ; if ( meta . extraMetadata ) { targetEntity . entityAspect . extraMetadata = meta . extraMetadata ; } // em._attachEntityCore(targetEntity, EntityState.Unchanged, MergeStrategy.Disallowed); em . _attachEntityCore ( targetEntity , EntityState . Unchanged , mergeStrategy ) ; targetEntity . entityAspect . wasLoaded = true ; em . entityChanged . publish ( { entityAction : EntityAction . AttachOnQuery , entity : targetEntity } ) ; } return targetEntity ; }
can return null for a deleted entity if includeDeleted == false
can return null for a deleted entity if includeDeleted == false