Advertisement
Guest User

Untitled

a guest
Mar 4th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity.Validation;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using zad8.Models;
  9.  
  10. namespace zad8
  11. {
  12. class Program
  13. {
  14. static void Main()
  15. {
  16. var contex = new UserContext();
  17. //contex.Database.Initialize(true);
  18. contex.Userrs.Add(new User()
  19. {
  20.  
  21. Username = "Stewart",
  22. Password = "YAK93CsFFX",
  23. Email = "Nam@acnulla.co.uk",
  24. RegisteredOn = new DateTime(11 / 12 / 2001),
  25. LastTimeLoggedIn = new DateTime(02 / 12 / 2015),
  26. Age = 18,
  27. IsDeleted = false
  28. });
  29.  
  30.  
  31. try
  32. {
  33. contex.SaveChanges();
  34. }
  35. catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
  36. {
  37. Exception raise = dbEx;
  38. foreach (var validationErrors in dbEx.EntityValidationErrors)
  39. {
  40. foreach (var validationError in validationErrors.ValidationErrors)
  41. {
  42. string message = string.Format("{0}:{1}",
  43. validationErrors.Entry.Entity.ToString(),
  44. validationError.ErrorMessage);
  45. // raise a new exception nesting
  46. // the current instance as InnerException
  47. raise = new InvalidOperationException(message, raise);
  48. }
  49. }
  50. throw raise;
  51. }
  52.  
  53.  
  54. }
  55.  
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement