/// <summary> /// Selects the specified attributes from the source columns. /// </summary> /// <typeparam name="TItem"> /// The type of the source item. /// </typeparam> /// <param name="matchSetAction"> /// Defines the set of matching attributes. /// </param> /// <param name="sourceAttributes"> /// The source attributes to return. /// </param> /// <returns> /// The current <see cref="JsonInsert{T}"/>. /// </returns> public TransactSqlMergeBase <T> SelectFromSource <TItem>( [NotNull] Action <AttributeMatchSet <T, TItem> > matchSetAction, [NotNull] params Expression <Func <TItem, object> >[] sourceAttributes) { if (matchSetAction == null) { throw new ArgumentNullException(nameof(matchSetAction)); } if (sourceAttributes == null) { throw new ArgumentNullException(nameof(sourceAttributes)); } var itemDefinition = this.DatabaseContext.RepositoryAdapter.DefinitionProvider.Resolve <TItem>(); var matchSet = new AttributeMatchSet <T, TItem>(); matchSetAction.Invoke(matchSet); this.targetSourceRelations.Clear(); foreach (var attributeMatch in matchSet.Matches) { var entityRelation = new EntityRelation(EntityRelationType.InnerJoin); entityRelation.Join(attributeMatch.SourceExpression, attributeMatch.RelationExpression); this.targetSourceRelations.Add(entityRelation); } this.sourceSelectionAttributes.AddRange( sourceAttributes.Any() ? sourceAttributes.Select(itemDefinition.Find) : itemDefinition.ReturnableAttributes); return(this); }
public void On_MatchedAttributeSet_ExpressionPropertyNamesMatchExpected() { var target = new AttributeMatchSet <DomainAggregateRow, SubContainerRow>().On(row => row.SubContainerId, row => row.SubContainerId); Assert.AreEqual(nameof(DomainAggregateRow.SubContainerId), target.Matches.First().SourceExpression.GetPropertyName()); Assert.AreEqual(nameof(SubContainerRow.SubContainerId), target.Matches.First().RelationExpression.GetPropertyName()); }