/// <summary> /// Associates a given entity with a store entity. This method is intended for use by scenarios where a /// client entity may represent a projection of one or multiple data store entities. /// </summary> /// <typeparam name="TEntity">The client entity type.</typeparam> /// <typeparam name="TStoreEntity">The data store entity type.</typeparam> /// <param name="clientEntity">The client entity.</param> /// <param name="storeEntity">The data store entity.</param> /// <param name="storeToClientTransform">The entity transform. This delegate will be invoked after the <see cref="ChangeSet"/> has /// been successfully submitted and is intended to flow <paramref name="storeEntity"/> values back to the /// <paramref name="clientEntity"/>.</param> /// <exception cref="ArgumentNullException">if <paramref name="clientEntity"/>, <paramref name="storeEntity"/> or /// <paramref name="storeToClientTransform"/> is null.</exception> public void Associate <TEntity, TStoreEntity>(TEntity clientEntity, TStoreEntity storeEntity, Action <TEntity, TStoreEntity> storeToClientTransform) where TEntity : class where TStoreEntity : class { if (clientEntity == null) { throw new ArgumentNullException("clientEntity"); } if (storeEntity == null) { throw new ArgumentNullException("storeEntity"); } if (storeToClientTransform == null) { throw new ArgumentNullException("storeToClientTransform"); } // Verify the provided client entity exists in our changeset this.VerifyExistsInChangeset(clientEntity); Action transformAction = () => storeToClientTransform(clientEntity, storeEntity); AssociatedEntityInfo associatedModel = new AssociatedEntityInfo(clientEntity, transformAction); List <AssociatedEntityInfo> associatedModels = null; if (!this.AssociatedStoreEntities.TryGetValue(storeEntity, out associatedModels)) { associatedModels = new List <AssociatedEntityInfo>(); this.AssociatedStoreEntities[storeEntity] = associatedModels; } associatedModels.Add(associatedModel); }
public void Associate <TEntity, TStoreEntity>(TEntity clientEntity, TStoreEntity storeEntity, Action <TEntity, TStoreEntity> storeToClientTransform) where TEntity : class where TStoreEntity : class { if (clientEntity == null) { throw new ArgumentNullException("clientEntity"); } if (storeEntity == null) { throw new ArgumentNullException("storeEntity"); } if (storeToClientTransform == null) { throw new ArgumentNullException("storeToClientTransform"); } this.VerifyExistsInChangeset(clientEntity); Action entityTransform = () => storeToClientTransform(clientEntity, storeEntity); AssociatedEntityInfo item = new AssociatedEntityInfo(clientEntity, entityTransform); List <AssociatedEntityInfo> list = null; if (!this.AssociatedStoreEntities.TryGetValue(storeEntity, out list)) { list = new List <AssociatedEntityInfo>(); this.AssociatedStoreEntities[storeEntity] = list; } list.Add(item); }