I need to consult records within the master detail from the master table. I have the purchases
table and the purchases detail
table, and I need to consult the purchases that contain the product collection.
Model params:
public class PurchaseParmsDto { public ICollection<Int32> ProductsId { get; set; } }
Query:
var query = (from p in _context.Purchase where p.DetailPurchase.Where(x => purchaseParms.ProductsId.Contains(x.IdProducto)) select new...)
I get this error when running the query:
Severity Code Description Project File Line Status deleted
Error CS0029 Cannot implicitly convert type’System.Collections.Generic.IEnumerable’ en ‘bool’
ApplicationComercio D:ProyectosAppComercioMultiApiApplicationComercioControllersPurchasesController.cs 163 Activo
Could you help me please? Thanks
Advertisement
Answer
replace any where.
This query allows you to search within the details of the master table, all the matching products
var query = ( from p in _context.Purchase where p.DetailPurchase.Any(x => purchaseParms.Products.Count==0|| purchaseParms.Products.Contains(x.IdProducto))