/// <summary> /// Adds a predicate that requires an attribute of the current <see cref="EntitySelection{T}"/> be found in the specified /// sub-query, /// represented by <paramref name="entitySet"/>. /// </summary> /// <param name="sourceAttribute"> /// The source attribute to require a match with. /// </param> /// <param name="entitySet"> /// The entity set to query. /// </param> /// <param name="matchAttribute"> /// The match attribute in the <paramref name="entitySet"/>. /// </param> /// <typeparam name="TSet"> /// The type of entity in which the match is to be found. /// </typeparam> /// <returns> /// The current <see cref="ValueFilterSet{T}"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="sourceAttribute"/>, <paramref name="entitySet"/>, or <paramref name="matchAttribute"/> is null. /// </exception> public ValueFilterSet <T> ExistsIn <TSet>( [NotNull] Expression <Func <T, object> > sourceAttribute, [NotNull] EntitySet <TSet> entitySet, [NotNull] Expression <Func <TSet, object> > matchAttribute) { if (entitySet == null) { throw new ArgumentNullException(nameof(entitySet)); } if (sourceAttribute == null) { throw new ArgumentNullException(nameof(sourceAttribute)); } if (matchAttribute == null) { throw new ArgumentNullException(nameof(matchAttribute)); } var entityRelation = new EntityRelation(EntityRelationType.InnerJoin); entityRelation.Join(sourceAttribute, matchAttribute); var entityRelations = new List <IEntityRelation> { entityRelation }; var setExpression = new RelationExpression(entitySet, entityRelations); this.valueFilters.Add(setExpression); return(this); }
/// <summary> /// Appends a LEFT JOIN clause to the selection. The table represented by <typeparamref name="TSource"/> must already be a /// JOIN member. /// </summary> /// <param name="leftSelector"> /// The left selector of the JOIN clause. /// </param> /// <param name="rightSelector"> /// The right selector of the JOIN clause. /// </param> /// <typeparam name="TSource"> /// The type of item on the left side of the LEFT JOIN. /// </typeparam> /// <typeparam name="TRelation"> /// The type of item on the right side of the LEFT JOIN. /// </typeparam> /// <returns> /// The current <see cref="EntityRelationSet{TItem}"/>. /// </returns> public EntityRelationSet <TEntity> LeftJoin <TSource, TRelation>( Expression <Func <TSource, object> > leftSelector, Expression <Func <TRelation, object> > rightSelector) { var entityRelation = new EntityRelation(EntityRelationType.LeftJoin); entityRelation.Join(leftSelector, rightSelector, null, null); return(this.AddRelation(entityRelation)); }
/// <summary> /// Appends a INNER JOIN clause to the selection. /// </summary> /// <param name="leftSelector"> /// The left selector of the JOIN clause. /// </param> /// <param name="rightSelector"> /// The right selector of the JOIN clause. /// </param> /// <typeparam name="TRelation"> /// The type of item on the right side of the INNER JOIN. /// </typeparam> /// <returns> /// The current <see cref="EntityRelationSet{TItem}"/>. /// </returns> public EntityRelationSet <TEntity> InnerJoin <TRelation>( Expression <Func <TEntity, object> > leftSelector, Expression <Func <TRelation, object> > rightSelector) { if (leftSelector == null) { throw new ArgumentNullException(nameof(leftSelector)); } if (rightSelector == null) { throw new ArgumentNullException(nameof(rightSelector)); } var entityRelation = new EntityRelation(EntityRelationType.InnerJoin); entityRelation.Join(leftSelector, rightSelector, null, null); return(this.AddRelation(entityRelation)); }
/// <summary> /// Appends a LEFT JOIN clause to the selection. /// </summary> /// <param name="leftSelector"> /// The left selector of the JOIN clause. /// </param> /// <param name="rightSelector"> /// The right selector of the JOIN clause. /// </param> /// <returns> /// The current <see cref="EntityRelationSet{TItem}"/>. /// </returns> public EntityRelationSet <TEntity> LeftJoin( [NotNull] Expression <Func <TEntity, object> > leftSelector, [NotNull] Expression <Func <TEntity, object> > rightSelector) { if (leftSelector == null) { throw new ArgumentNullException(nameof(leftSelector)); } if (rightSelector == null) { throw new ArgumentNullException(nameof(rightSelector)); } var relation = new EntityRelation(EntityRelationType.LeftJoin); relation.Join <TEntity>(leftSelector, rightSelector); return(this.AddRelation(relation)); }
/// <summary> /// Appends a LEFT JOIN clause to the selection. The table represented by <typeparamref name="TSource"/> must already be a /// JOIN member. /// </summary> /// <param name="leftSelector"> /// The left selector of the JOIN clause. /// </param> /// <param name="sourceAlias"> /// The relation table alias. /// </param> /// <param name="rightSelector"> /// The right selector of the JOIN clause. /// </param> /// <param name="relationAlias"> /// The join table alias. /// </param> /// <typeparam name="TSource"> /// The type of item on the left side of the LEFT JOIN. /// </typeparam> /// <typeparam name="TRelation"> /// The type of item on the right side of the LEFT JOIN. /// </typeparam> /// <returns> /// The current <see cref="EntityRelationSet{TItem}"/>. /// </returns> public EntityRelationSet <TEntity> LeftJoin <TSource, TRelation>( Expression <Func <TSource, object> > leftSelector, string sourceAlias, Expression <Func <TRelation, object> > rightSelector, string relationAlias) { if (leftSelector == null) { throw new ArgumentNullException(nameof(leftSelector)); } if (rightSelector == null) { throw new ArgumentNullException(nameof(rightSelector)); } var entityRelation = new EntityRelation(EntityRelationType.LeftJoin); entityRelation.Join(leftSelector, rightSelector, sourceAlias, relationAlias); return(this.AddRelation(entityRelation)); }
/// <summary> /// Creates a selection based on the current entity expression. /// </summary> /// <param name="matchAttributes"> /// The attributes that match between the entity expression and the target selection. /// </param> /// <typeparam name="TSelection"> /// The type of entity to be returned by the target selection. /// </typeparam> /// <returns> /// A new <see cref="EntitySelection{T}"/> for entities of type <typeparamref name="TSelection"/>, with the current entity expression as the /// <see cref="EntitySet{T}.ParentExpression"/>. /// </returns> /// <exception cref="ArgumentNullException"> /// <paramref name="matchAttributes"/> is null. /// </exception> public EntitySelection <TSelection> ForSelection <TSelection>([NotNull] Action <AttributeMatchSet <T, TSelection> > matchAttributes) { if (matchAttributes == null) { throw new ArgumentNullException(nameof(matchAttributes)); } var attributeMatchSet = new AttributeMatchSet <T, TSelection>(); matchAttributes.Invoke(attributeMatchSet); foreach (var attributeMatch in attributeMatchSet.Matches) { var entityRelation = new EntityRelation(EntityRelationType.InnerJoin); entityRelation.Join(attributeMatch.SourceExpression, attributeMatch.RelationExpression); this.relations.Add(entityRelation); } var selection = new EntitySelection <TSelection>(); selection.WithAs(this); return(selection); }