Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data.Entity.Validation;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using zad8.Models;
- namespace zad8
- {
- class Program
- {
- static void Main()
- {
- var contex = new UserContext();
- //contex.Database.Initialize(true);
- contex.Userrs.Add(new User()
- {
- Username = "Stewart",
- Password = "YAK93CsFFX",
- Email = "Nam@acnulla.co.uk",
- RegisteredOn = new DateTime(11 / 12 / 2001),
- LastTimeLoggedIn = new DateTime(02 / 12 / 2015),
- Age = 18,
- IsDeleted = false
- });
- try
- {
- contex.SaveChanges();
- }
- catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
- {
- Exception raise = dbEx;
- foreach (var validationErrors in dbEx.EntityValidationErrors)
- {
- foreach (var validationError in validationErrors.ValidationErrors)
- {
- string message = string.Format("{0}:{1}",
- validationErrors.Entry.Entity.ToString(),
- validationError.ErrorMessage);
- // raise a new exception nesting
- // the current instance as InnerException
- raise = new InvalidOperationException(message, raise);
- }
- }
- throw raise;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement