Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [Table("clients")]
- public class ClientDto : BaseModelDto
- {
- [Required]
- [StringLength(70, MinimumLength = 3)]
- [Column("fio")]
- public string FIO { get; set; }
- [StringLength(100, MinimumLength = 3)]
- [Column("address")]
- public string Address { get; set; }
- [Phone]
- [Column("phone")]
- public string Phone { get; set; }
- public List<RealizationDto> Realizations { get; set; }
- }
- public async Task<ClientDto> GetTheMostValuableCustomer()
- {
- var result = await Context.Clients.FromSql<ClientDto>(@"
- select clients.id, clients.fio, clients.address, clients.phone, sum(goods.price*realizations.quantity) max_cost
- from clients
- inner join realizations on clients.id=realizations.client_id
- inner join goods on realizations.good_id=goods.id
- group by clients.id
- order by max_cost desc
- limit 1;
- ").ToListAsync();
- return result.FirstOrDefault();
- }
Add Comment
Please, Sign In to add comment