简体   繁体   English

如何使用 linq asp.net 内核

[英]How to using linq asp.net core

Could someone help me explaining how can I do this?有人可以帮我解释我该怎么做吗?

I need to list my products by categories (working fine at the moment), but now I need to check if each product listed is part of user's 'wishlist'.我需要按类别列出我的产品(目前工作正常),但现在我需要检查列出的每个产品是否是用户“愿望清单”的一部分。 If yes, need to show a different icon color, for example.如果是,例如需要显示不同的图标颜色。

在此处输入图像描述

Controller: Controller:

// Products Id
var produtosId = _context.Product
                         .Where(m => m.IdProdutoCategoria == idCategoria || 
                                     m.IdProdutoCategoriaNavigation.IdPai.Value == 1)
                         .Where(m => m.IsAtivo.Equals(true))
                         .GroupBy(m => m.Nome)
                         .Select(m => m.Min(p => p.IdProduto));

// products list
var products = await _context.Product
                             .Where(p => produtosId.Contains(p.IdProduto))
                             .Include(p => p.IdProdutoCategoriaNavigation)
                             .Include(p => p.IdProdutoTamanhoNavigation)
                             .Include(p => p.IdProdutoTipoMassaNavigation)
                             //.Include(p => p.WishList.Contains()
                             .ToListAsync()
                             .ConfigureAwait(true);

return View(products);

View:看法:

@* WishList Icon *@
<div class="WishList" data-id="@item.IdProduto" style="cursor: pointer">
    <i class="@( item.XXXX == XX ? "fas fa-heart" : "far fa-heart") fa-1x text-success float-right mr-2 mb-2"></i>
</div>
.Where(p => _context.WishList.Any(wl => wl.IdProduto == p.IdProduto))
var products = await _context.Product
        .Where(p => produtosId.Contains(p.IdProduto))
        .Include(p => p.IdProdutoCategoriaNavigation)
        .Include(p => p.IdProdutoTamanhoNavigation)
        .Include(p => p.IdProdutoTipoMassaNavigation)
        .Where(p => _context.WishList.Any(wl => wl.IdProduto == p.IdProduto))
        .ToListAsync()
        .ConfigureAwait(true)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM