Guest User

Untitled

a guest
Dec 13th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. [Table("clients")]
  2. public class ClientDto : BaseModelDto
  3. {
  4. [Required]
  5. [StringLength(70, MinimumLength = 3)]
  6. [Column("fio")]
  7. public string FIO { get; set; }
  8.  
  9. [StringLength(100, MinimumLength = 3)]
  10. [Column("address")]
  11. public string Address { get; set; }
  12.  
  13. [Phone]
  14. [Column("phone")]
  15. public string Phone { get; set; }
  16.  
  17. public List<RealizationDto> Realizations { get; set; }
  18. }
  19.  
  20. public async Task<ClientDto> GetTheMostValuableCustomer()
  21. {
  22. var result = await Context.Clients.FromSql<ClientDto>(@"
  23. select clients.id, clients.fio, clients.address, clients.phone, sum(goods.price*realizations.quantity) max_cost
  24. from clients
  25. inner join realizations on clients.id=realizations.client_id
  26. inner join goods on realizations.good_id=goods.id
  27. group by clients.id
  28. order by max_cost desc
  29. limit 1;
  30. ").ToListAsync();
  31.  
  32. return result.FirstOrDefault();
  33. }
Add Comment
Please, Sign In to add comment