Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

78
Views
Unir dos tablas y filtrar para recuperar Nombre

Este código está funcionando bien como se esperaba.

 var soldQtyForEachItem = await _context.InvoiceProduct .Where(x => x.ProductId != 0) .GroupBy(x => x.ProductId) .Select(grp => new CompanyProducts { CompanyProductId = grp.Key, CompanyProductSoldQuantity = grp.Sum(item => item.QuantitySold) }).ToListAsync();

Pregunta :

Ahora necesito unirme a otra tabla llamada Productos y filtrar por Id contra la tabla InvoiceProduct y recuperar ProductsItemName que es una fila de la tabla Productos; entonces todos deben ir a un tipo personalizado "CompanyProducts" a continuación.

Por favor como lo logro?


 public class CompanyProducts { public int CompanyProductId { get; set; } public int CompanyProductName { get; set; } public int CompanyProductSoldQuantity { get; set; } }

La tabla InvoiceProduct es de muchos a muchos, lo que significa que un InvoiceId puede tener varios ProductId.

La tabla de productos tiene propiedades como ProductId, ProductsItemName.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

La solución más simple es incluir ProductItemName en la agrupación:

 var soldQtyForEachItem = await _context.InvoiceProduct .Where(x => x.ProductId != 0) .GroupBy(x => new { x.ProductId, x.Product.ProductsItemName } ) .Select(grp => new CompanyProducts { CompanyProductId = grp.Key.ProductId, CompanyProductName = grp.Key.ProductsItemName, CompanyProductSoldQuantity = grp.Sum(item => item.QuantitySold) }) .ToListAsync();
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!