-2
It would be possible to consult the table below in a single query?
It would be a group by query using Context with Entity Framework where:
The 3 customers who spent the most on services per month in the current year according to table :
The tables would be:
-client table: Name; Neighborhood; City; State;
namespace ServicosPrestados.Models
{
public class Cliente
{
public int Id { get; set; }
public string Nome { get; set; }
public string Bairro { get; set; }
public string Cidade { get; set; }
public string Estado { get; set; }
}
}
-Table of services provided: Description of service Call date Service value
namespace ServicosPrestados.Models.Entidades
{
public class Servico
{
public int Id { get; set; }
public string Descricao { get; set; }
public DateTime Data { get; set; }
public decimal Valor { get; set; }
public virtual Cliente Cliente { get; set; }
public int IdCliente { get; set; }
}
}
mapping:
using ServicosPrestados.Models.Entidades;
using System.Data.Entity.ModelConfiguration;
namespace ServicosPrestados.Models.Mapeamento
{
public class ServicoMapeamento : EntityTypeConfiguration<Servico>
{
public ServicoMapeamento()
{
ToTable("SERVICO");
HasKey(x => x.Id);
Property(x => x.IdCliente)
.HasColumnName("ID_CLIENTE")
.HasColumnType("int")
.IsRequired();
Property(x => x.Descricao)
.HasColumnName("DESCRICAO")
.HasColumnType("varchar")
.HasMaxLength(100)
.IsRequired();
Property(x => x.Data)
.HasColumnName("DATA")
.HasColumnType("datetime")
.IsRequired();
Property(x => x.Valor)
.HasColumnName("VALOR")
.HasColumnType("decimal")
.IsRequired();
HasRequired(m => m.Cliente).WithMany().HasForeignKey(m => m.IdCliente);
}
}
}

Yes, it is possible. Give more details: is it EF, is it another Provider or do you want to do in memory? What are the sets that contain this data called? Service records are directly linked to
Cliente? If yes, by what property? Without this it is even possible to answer, but it will become something either very abstract or very long– Jéf Bueno
is EF . is simple foreign key Client -> Service (id) using virtual.
– Elton A. Pering
It would be nice to [Dit] your question and add this information.
– Jéf Bueno
Look, how could you answer without seeing the context class and the models? Post this too, but please post only the part needed to answer the question.
– Jéf Bueno
see if they need anything else
– Elton A. Pering