Guest User

Untitled

a guest
Jan 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. // Combo of Dapper, EF and a stored proc that was published through SSDT
  2. static void Main(string[] args)
  3. {
  4. var connectionString = ConfigurationManager
  5. .ConnectionStrings["DbDataContext"].ConnectionString;
  6.  
  7. using (var conn = new SqlConnection(connectionString))
  8. using (var ctx = new DbDataContext())
  9. {
  10. conn.Open();
  11.  
  12. var product = conn.Query<Product>("GetProduct",
  13. commandType: CommandType.StoredProcedure).First();
  14.  
  15. ctx.Products.Attach(product);
  16.  
  17. var order = new Order
  18. {
  19. Product = product
  20. };
  21.  
  22. ctx.Orders.Add(order);
  23.  
  24. ctx.SaveChanges();
  25.  
  26. }
  27. }
Add Comment
Please, Sign In to add comment