L
L
lucky42021-04-28 13:13:42
C++ / C#
lucky4, 2021-04-28 13:13:42

How to pull data from linq?

I make a type output of products from a certain category. There is the Products entity, into which its category is loaded by eager loading, and the structure turns out like this:

{
   "id": 6,
   "label": "Opillya Koryfey live light beer 3.7% 0.5l",
   "price": 23.49,
   "description": "500 ml",
   "thumbnail": "https://img3.zakaz.ua/src.1597741190.ad72436478c_2020-08-18_Alina/src.1597741190.SNCPSG10.obj.0.1.jpg.oe.jpg.pf.jpg.150nowm.jpg.150x.jpg",
   "category": [
      {
         "id": 1,
         "label": "Beer"
      }
   ]
},


Here the problem arises, how do I reach category.id?
public async Task<IList<Product>> GetProductsByCategory(int offset, int limit,
            string searchProperty, string searchValue,
            string orderBy, bool desc, int categoryID)
        { 
            return await _context.Set<Product>()
                .Include(property => property.ProductCategories)
                .ThenInclude(property => property.Category)
                //как пройти к Category.Id?
                //.Where(property => property.)
                .ApplyFiltering(searchProperty, searchValue)
                .ApplyOrdering(orderBy, desc)
                .Skip(offset)
                .Take(limit)
                .ToListAsync();
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lucky4, 2021-04-28
@lucky4

.Where(x => x.ProductCategories.Any(x => x.CategoryId == categoryId))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question