Guest User

Untitled

a guest
Jul 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. // sync
  2. Product produto = null;
  3. using (var cn = new SqlConnection(configuration.GetConnectionString("DefaultConnection")))
  4. {
  5. var query = @"
  6. SELECT * FROM Products WHERE ProductID = @Id
  7. SELECT * FROM [Order Details] WHERE ProductID = @Id
  8. ";
  9. using (var result = cn.QueryMultiple(query, new { id }))
  10. {
  11. produto = result.Read<Product>().Single();
  12. produto.OrderDetails = result.Read<OrderDetail>().ToList();
  13. }
  14. }
  15. // async
  16. Product produto = null;
  17. using (var cn = new SqlConnection(configuration.GetConnectionString("DefaultConnection")))
  18. {
  19. var query = @"
  20. SELECT * FROM Products WHERE ProductID = @Id
  21. SELECT * FROM [Order Details] WHERE ProductID = @Id
  22. ";
  23. using (var result = await cn.QueryMultipleAsync(query, new { id }))
  24. {
  25. produto = await result.ReadFirstAsync<Product>();
  26. produto.OrderDetails = (await result.ReadAsync<OrderDetail>()).ToList();
  27. }
  28. }
Add Comment
Please, Sign In to add comment