예제 #1
0
        /// <summary>
        /// Method to get a <see cref="IEnumerable{T}"/> list of <see cref="PictureEntity"/> from database.
        /// </summary>
        /// <param name="op">The <see cref="PictureOptionsList"/> list of options for filter the query.</param>
        /// <returns>An <see cref="IEnumerable{T}"/> list of <see cref="PictureEntity"/>.</returns>
        public IEnumerable <PictureEntity> List(PictureOptionsList op = default(PictureOptionsList))
        {
            // Initialize default option list.
            op = op ?? new PictureOptionsList {
            };

            // Initialize query.
            IQueryable <PictureEntity> query = Connector.Pictures;

            // Load dependencies if required.
            QueryDependencies(ref query, op);

            // Load dependencies if required.
            QueryFilterAlbums(ref query, op);

            // Check for filter primary keys to search in.
            query.QueryListFilter(op);

            // Set number elements to skip & the number elements to select.
            query.QueryStartLimit(op);



            // Return a list of entities.
            return(query.ToList());
        }
예제 #2
0
        /// <summary>
        /// Method to filter by <see cref="AlbumEntity"/> a <see cref="IQueryable"/> query of <see cref="PictureEntity"/>.
        /// </summary>
        /// <param name="query">A <see cref="IQueryable"/> query of <see cref="PictureEntity"/>.</param>
        /// <param name="op">The <see cref="PictureOptionsList"/> list of options for filter the query.</param>
        /// <returns>A list of Section entities.</returns>
        private void QueryFilterAlbums(ref IQueryable <PictureEntity> query, PictureOptionsList op = default(PictureOptionsList))
        {
            // Initialize default option list.
            op = op ?? new PictureOptionsList {
            };

            // Check for the desired album associations.
            if (op.IncludeAlbumId != null && op.IncludeAlbumId.Count > 0)
            {
                query.Where(x => x.PicturesInAlbums.Any(y => op.IncludeAlbumId.Contains(y.AlbumId)));
            }

            // Check for the undesired album association.
            if (op.ExcludeAlbumId != null && op.ExcludeAlbumId.Count > 0)
            {
                query.Where(x => !x.PicturesInAlbums.Any(y => op.IncludeAlbumId.Contains(y.AlbumId)));
            }
        }