public void ExistsIn_EntityOutsideAggregateRelations_MatchesExpected() { var target = new ValueFilterSet <DomainAggregateRow>().ExistsIn( row => row.DomainAggregateId, Query.From <DomainAggregateFlagAttributeRow>( set => set.InnerJoin <FlagAttributeRow>(row => row.FlagAttributeId, row => row.FlagAttributeId)) .Where(set => set.Include((FlagAttributeRow row) => row.Name, "type1", "type2", "type3")), row => row.DomainAggregateId); Assert.IsTrue(target.ValueFilters.Any()); Assert.AreEqual(1, target.ValueFilters.Count()); Assert.AreEqual(3, (target.ValueFilters.First() as RelationExpression)?.FilterValues.Count()); CollectionAssert.AreEqual( new[] { "type1", "type2", "type3" }, (target.ValueFilters.First() as RelationExpression)?.EntitySet.Filters.First().FilterValues.OfType <string>().ToList()); var expectedRelation = new EntityRelation(EntityRelationType.InnerJoin); expectedRelation.Join <DomainAggregateRow, DomainAggregateFlagAttributeRow>(row => row.DomainAggregateId, row => row.DomainAggregateId); Assert.AreEqual(expectedRelation, (target.ValueFilters.First() as RelationExpression)?.Relations.First()); }
/// <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 Join_ExplicitSourceAndRelationTypes_EntityRelationMatchesExpected() { var definitionProvider = new DataAnnotationsDefinitionProvider(); var actual = new EntityRelation(EntityRelationType.InnerJoin); actual.Join <FakeRelatedRow, DependencyRow>(row => row.RelatedId, row => row.FakeDependencyEntityId); var relatedDefinition = definitionProvider.Resolve <FakeRelatedRow>(); var leftDefinition = relatedDefinition; var leftReference = new EntityReference { EntityType = typeof(FakeRelatedRow) }; var leftLocation = definitionProvider.GetEntityLocation(leftReference); var leftAttributeLocation = new AttributeLocation(typeof(FakeRelatedRow).GetProperty(nameof(FakeRelatedRow.RelatedId)), leftReference); var leftAttribute = leftDefinition.Find(leftAttributeLocation); Assert.AreEqual(leftLocation, relatedDefinition.Find(actual.SourceExpression).Entity); Assert.AreEqual(leftAttribute, relatedDefinition.Find(actual.SourceExpression)); var rightDefinition = definitionProvider.Resolve <DependencyRow>(); var rightReference = new EntityReference { EntityType = typeof(DependencyRow) }; var rightLocation = definitionProvider.GetEntityLocation(rightReference); var rightAttributeLocation = new AttributeLocation(typeof(DependencyRow).GetProperty(nameof(DependencyRow.FakeDependencyEntityId)), rightReference); var rightAttribute = rightDefinition.Find(rightAttributeLocation); Assert.AreEqual(rightLocation, rightDefinition.Find(actual.RelationExpression).Entity); Assert.AreEqual(rightAttribute, rightDefinition.Find(actual.RelationExpression)); }
public void Join_LocalAttributeToRelatedAttribute_MatchesExpected() { var definitionProvider = new DataAnnotationsDefinitionProvider(); var actual = new EntityRelation(EntityRelationType.InnerJoin); actual.Join <ChildRaisedRow>(row => row.ComplexEntityId, row => row.ComplexEntity.ComplexEntityId); var childDefinition = definitionProvider.Resolve <ChildRaisedRow>(); var childReference = new EntityReference { EntityType = typeof(ChildRaisedRow) }; var childLocation = definitionProvider.GetEntityLocation(childReference); var childAttributeLocation = new AttributeLocation(typeof(ChildRaisedRow).GetProperty("ComplexEntityId"), childReference); var childComplexIdAttribute = childDefinition.Find(childAttributeLocation); Assert.AreEqual(childLocation, childDefinition.Find(actual.SourceExpression).Entity); Assert.AreEqual(childComplexIdAttribute, childDefinition.Find(actual.SourceExpression)); //// actual.SourceAttribute); var complexDefinition = definitionProvider.Resolve <ComplexRaisedRow>(); var complexReference = new EntityReference { EntityType = typeof(ComplexRaisedRow) }; var complexLocation = definitionProvider.GetEntityLocation(complexReference); var complexAttributeLocation = new AttributeLocation(typeof(ComplexRaisedRow).GetProperty("ComplexEntityId"), complexReference); var complexIdAttribute = complexDefinition.Find(complexAttributeLocation); Assert.AreEqual(complexLocation, complexDefinition.Find(actual.RelationExpression).Entity); //// actual.RelationLocation); Assert.AreEqual(complexIdAttribute, complexDefinition.Find(actual.RelationExpression)); }
public void LeftJoin_TwoExternalRelationsWithRelationAlias_MatchesExpected() { var actual = new EntityRelationSet <DataRow>().LeftJoin <RelatedRow, DependencyRow>( row => row.RelatedRowId, row => row.FakeDependencyEntityId, "My Alias").Relations.First(); var expected = new EntityRelation(EntityRelationType.LeftJoin); expected.Join <RelatedRow, DependencyRow>(row => row.RelatedRowId, row => row.FakeDependencyEntityId, null, "My Alias"); Assert.AreEqual(expected, actual); }
public void LeftJoin_EntityRelationSetWithTwoExternalRelations_MatchesExpected() { var relations = new EntityRelationSet <DataRow>().LeftJoin <FakeRelatedRow, DependencyRow>( row => row.RelatedId, row => row.FakeDependencyEntityId, "Alias").Relations; var expected = new EntityRelation(EntityRelationType.LeftJoin); expected.Join <FakeRelatedRow, DependencyRow>(row => row.RelatedId, row => row.FakeDependencyEntityId, null, "Alias"); Assert.IsNotNull(relations.FirstOrDefault(x => expected == (EntityRelation)x)); }
public void LeftJoin_InferredWithMatchingSourceAndRelationProperties_MatchesExpected() { var relations = new EntityRelationSet <DataRow>() .LeftJoin(row => row.Related.RelatedId, row => row.DependencyEntity.ComplexEntityId) .Relations; var expected = new EntityRelation(EntityRelationType.LeftJoin); expected.Join <FakeRelatedRow, DependencyRow>(row => row.RelatedId, row => row.ComplexEntityId); Assert.IsNotNull(relations.FirstOrDefault(x => expected == (EntityRelation)x)); }
public void LeftJoin_InferredWithMatchingRelationProperty_MatchesExpected() { var relations = new EntityRelationSet <DataRow>() .LeftJoin(row => row.FakeDataId, row => row.Related.FakeDataId) ////.InnerJoin(row => row.Related, row => row.DependencyEntity, row => row.RelatedId, row => row.ComplexEntityId) ////.InnerJoin(row => row.OtherAlias, row => row.FakeDataId, row => row.FakeDataId) ////.InnerJoin(row => row.OtherAlias, row => row.RelatedDependency, row => row.RelatedId, row => row.ComplexEntityId) ////.InnerJoin(row => row.RelatedAlias, row => row.FakeDataId, row => row.FakeDataId) .Relations; var expected = new EntityRelation(EntityRelationType.LeftJoin); expected.Join <DataRow, FakeRelatedRow>(row => row.FakeDataId, row => row.FakeDataId); Assert.IsNotNull(relations.FirstOrDefault(x => expected == (EntityRelation)x)); }
public void InnerJoin_WithRelationAlias_MatchesExpected() { var relations = new EntityRelationSet <DataRow>() ////.InnerJoin<FakeRelatedRow>(row => row.FakeDataId, row => row.FakeDataId) ////.InnerJoin<FakeRelatedRow, DependencyRow>(row => row.RelatedId, row => row.ComplexEntityId) .InnerJoin <FakeRelatedRow>(row => row.FakeDataId, row => row.FakeDataId, "OtherAlias") ////.InnerJoin<FakeRelatedRow, DependencyRow>( //// row => row.RelatedId, //// "OtherAlias", //// row => row.ComplexEntityId, //// "RelatedDependency") ////.InnerJoin<FakeRelatedRow>(row => row.FakeDataId, row => row.FakeDataId, "RelatedAlias") .Relations; var expected = new EntityRelation(EntityRelationType.InnerJoin); expected.Join <DataRow, FakeRelatedRow>(row => row.FakeDataId, row => row.FakeDataId, null, "OtherAlias"); var actual = relations.FirstOrDefault(); Assert.AreEqual(expected, actual); }