コード例 #1
0
ファイル: Example.cs プロジェクト: mholec/skolenicodefirst
        public void ValidationDisabled()
        {
            using (var db = new MyContext())
            {
                Database.SetInitializer(new DropCreateDatabaseAlways<MyContext>());

                Article articleLengthTest = new Article
                {
                    Title = "My Title",
                    Description = "Short text"
                };

                db.Articles.Add(articleLengthTest);
                db.Configuration.ValidateOnSaveEnabled = false;
                db.SaveChanges(); // uložení projde, protože MinLength() není db constraint
            }
        }
コード例 #2
0
ファイル: Example.cs プロジェクト: mholec/skolenicodefirst
        public void ValidationFailed()
        {
            using (var db = new MyContext())
            {
                Database.SetInitializer(new DropCreateDatabaseAlways<MyContext>());

                Article articleLengthTest = new Article
                {
                    Title = "My Title",
                    Description = "Short text"
                };

                db.Articles.Add(articleLengthTest);
                db.SaveChanges();
            }
        }