Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. class Program
  2. {
  3. static Model1 d = new Model1();
  4. static void Main(string[] args)
  5. {
  6. save(); // 1 //success
  7. save(); // 2 //error
  8. save("xxx"); //3 //why this got error?, when i check Sql Server Profiler, query same with No 2, error duplicate, it should not be error, because the id is not the same
  9. }
  10.  
  11. private static void save(string id="zzz")
  12. {
  13. try
  14. {
  15. d.Cage.Add(new Cage()
  16. {
  17. CageId = id, // id cant same
  18. CreatedOn = DateTime.Now,
  19. UpdatedOn = DateTime.Now,
  20. Depreciation = 0
  21. });
  22. d.SaveChanges();
  23. }
  24. catch (Exception)
  25. {
  26. Console.WriteLine("Error");
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement