Ejemplo n.º 1
0
        public IEnumerable <string> Run()
        {
            List <string> errorMessages = new List <string>();

            Database.SetInitializer(new DropCreateDatabaseAlways <FamilyMembersWithValidation>());
            var context = new FamilyMembersWithValidation();

            var chris = new Dad()
            {
                FirstName = "Chris",
                Address   = new Address()
            };

            try
            {
                context.Dads.Add(chris);

                errorMessages.AddRange(ValidationHelper.ExtractValidationMessages(context));

                context.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
                errorMessages.Add("Exception thrown when trying to save dad " + ex.ToString());
            }

            return(errorMessages);
        }
        public IEnumerable<string> Run()
        {
            List<string> errorMessages = new List<string>();
            Database.SetInitializer(new DropCreateDatabaseAlways<FamilyMembersWithValidation>());
            var context = new FamilyMembersWithValidation();

            var chris = new Dad()
            {
                FirstName = "Chris",
                Address = new Address()
            };

            try
            {
                context.Dads.Add(chris);

                errorMessages.AddRange(ValidationHelper.ExtractValidationMessages(context));

                context.SaveChanges();
            }
            catch(DbEntityValidationException ex)
            {
                errorMessages.Add("Exception thrown when trying to save dad " + ex.ToString());
            }

            return errorMessages;
        }