public IEnumerable <string> Run()
        {
            List <string> errorMessages = new List <string>();

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

            var chris = new Dad()
            {
                FirstName = "Chris this is a really long name........",
                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);
        }
Example #2
0
        public IEnumerable <string> Run()
        {
            Database.SetInitializer(new OrtmanFamilyInitializer());
            var context = new FamilyMembersWithAttributes();

            context.Database.Delete();
            context.Database.Initialize(true);

            return(Enumerable.Empty <string>());
        }
        public IEnumerable <string> Run()
        {
            List <string> errorMessages = new List <string>();

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

            var chris = new Dad()
            {
                FirstName = "Chris",
                Address   = new Address()
                {
                    City  = "Ethan",
                    State = "SD",
                    Zip   = "9999999999"
                }
            };

            var otherDad = new Dad()
            {
                FirstName = "Dad with short zip code",
                Address   = new Address()
                {
                    Zip = "1"
                }
            };



            try
            {
                context.Dads.Add(chris);
                context.Dads.Add(otherDad);

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

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

            return(errorMessages);
        }
Example #4
0
        public IEnumerable <string> Run()
        {
            Database.SetInitializer(new OrtmanFamilyInitializer());
            var context = new FamilyMembersWithAttributes();

            //since i know i've only just created 1 dad, i just hardcode the ID
            var chris = context.Dads.First(x => x.FirstName == "Chris");

            var clara = new Kid()
            {
                Name = "Clara", Birthday = DateTime.Parse("1/21/2009")
            };

            chris.Kids.Add(clara);

            var message = new Message("Data inserted via attributes demo");

            context.Messages.Add(message);
            context.SaveChanges();

            return(Enumerable.Empty <string>());
        }