Why this query returns the same products multiple times?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
I had a request from a client to build a specific page where I should show all the products having discounts from ALL categories, ordered by categories.

All works great but some products are returned multiple times. This is the query I've built:

public virtual IPagedList<Product> GetAllProductsWithDiscount(int languageId, int pageIndex, int pageSize)
        {
            var query = from p in _productRepository.Table
                        from pv in p.ProductVariants.DefaultIfEmpty()
                        from pc in p.ProductCategories
                        where pv.OldPrice != 0
                        && pv.OldPrice != pv.Price
                        && p.Deleted == false
                        && (pv.AvailableEndDateTimeUtc == null
                        || pv.AvailableEndDateTimeUtc > DateTime.Now)
                        && pv.Published == true
                        orderby pc.CategoryId
                         select p;
            var products = new PagedList<Product>(query, pageIndex, pageSize);
            return products;
            
        }


I simply cannot figure out why if I remove the join with ProductCategories all works nice but as it is now, it has the issue described above.

Is there anybody here who can help me with this?

thanks in advance,
12 years ago
one Product can be in more than one Category
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.