pick up customer with certain types of purchases

0

I have these tables:

  

Sales: SalesList (int) PK, SalesDate (DateTime), QdeItem (Decimal),   Sales Value (Decimal) .IDItem (FK), CustomerID (FK)

     

Item: IDItem (int) PK, Description (Varchar), ValueItem (Decimal)

     

Client: CustomerID (int) PK, Name (varchar), DataCadastro (DateTime)

How do I filter only those customers who bought 5 or more bikes and a tire at least using LINQ only?

    
asked by anonymous 30.03.2015 / 16:28

1 answer

1

You can perform the following query:

public IEnumerable<int> getClientes(int itemID, int qtdMinimo)
{
    return (
        from venda in db.Vendas
        where venda.IDItem == itemID
        group venda by venda.IDCliente into grupo
        where grupo.Sum(venda => venda.QdeItem) >= qtdMinimo
        select grp.Key
    );
}

In the above case, all customers who bought more than 5 product items will be returned regardless of whether these products were purchased in the same order.

P.S: Not tested

    
30.03.2015 / 16:58