Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // sync
- Product produto = null;
- using (var cn = new SqlConnection(configuration.GetConnectionString("DefaultConnection")))
- {
- var query = @"
- SELECT * FROM Products WHERE ProductID = @Id
- SELECT * FROM [Order Details] WHERE ProductID = @Id
- ";
- using (var result = cn.QueryMultiple(query, new { id }))
- {
- produto = result.Read<Product>().Single();
- produto.OrderDetails = result.Read<OrderDetail>().ToList();
- }
- }
- // async
- Product produto = null;
- using (var cn = new SqlConnection(configuration.GetConnectionString("DefaultConnection")))
- {
- var query = @"
- SELECT * FROM Products WHERE ProductID = @Id
- SELECT * FROM [Order Details] WHERE ProductID = @Id
- ";
- using (var result = await cn.QueryMultipleAsync(query, new { id }))
- {
- produto = await result.ReadFirstAsync<Product>();
- produto.OrderDetails = (await result.ReadAsync<OrderDetail>()).ToList();
- }
- }
Add Comment
Please, Sign In to add comment