Esempio n. 1
0
        /// <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));
        }
Esempio n. 2
0
        /// <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));
        }
Esempio n. 3
0
        /// <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));
        }
Esempio n. 4
0
        /// <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);
        }