Esempio n. 1
0
        /// <summary>
        /// Get an IQueryable of parents matching a supplied IQueryable of children for this relationship.
        /// </summary>
        /// <typeparam name="TParent">The type of the parent Entity</typeparam>
        /// <param name="children">An IQueryable of children</param>
        /// <param name="options">An optional AggregateOptions object</param>
        public IMongoQueryable <TParent> ParentsQueryable <TParent>(IMongoQueryable <TChild> children, AggregateOptions options = null) where TParent : Entity
        {
            if (typeof(TParent) == typeof(TChild))
            {
                throw new InvalidOperationException("Both parent and child types cannot be the same");
            }

            if (inverse)
            {
                return(children
                       .Join(
                           JoinQueryable(options),
                           c => c.ID,
                           j => j.ParentID,
                           (c, j) => j)
                       .Join(
                           DB.Collection <TParent>(),
                           j => j.ChildID,
                           p => p.ID,
                           (j, p) => p)
                       .Distinct());
            }
            else
            {
                return(children
                       .Join(
                           JoinQueryable(options),
                           c => c.ID,
                           j => j.ChildID,
                           (c, j) => j)
                       .Join(
                           DB.Collection <TParent>(),
                           j => j.ParentID,
                           p => p.ID,
                           (j, p) => p)
                       .Distinct());
            }
        }