當前位置: 首頁>>代碼示例>>C#>>正文


C# Blog.Delete方法代碼示例

本文整理匯總了C#中Blog.Delete方法的典型用法代碼示例。如果您正苦於以下問題:C# Blog.Delete方法的具體用法?C# Blog.Delete怎麽用?C# Blog.Delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Blog的用法示例。


在下文中一共展示了Blog.Delete方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Delete

        public void Delete()
        {
            Blog[] blogs = Blog.FindAll();

            Assert.IsNotNull(blogs);
            Assert.AreEqual(0, blogs.Length);

            Blog blog = new Blog();
            blog.Name = "hammett's blog";
            blog.Author = "hamilton verissimo";
            blog.Save();

            blogs = Blog.FindAll();

            Assert.IsNotNull(blogs);
            Assert.AreEqual(1, blogs.Length);

            blog.Delete();

            blogs = Blog.FindAll();

            Assert.IsNotNull(blogs);
            Assert.AreEqual(0, blogs.Length);
        }
開發者ID:zhoufoxcn,項目名稱:ActiveRecord,代碼行數:24,代碼來源:ActiveRecordBaseGenericsTestCase.cs

示例2: Delete

        public void Delete()
        {
            using (new SessionScope()) {
                var blogs = Blog.FindAll();

                Assert.IsNotNull(blogs);
                Assert.AreEqual(10, blogs.Count());

                var blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};
                blog.Save();

                blogs = Blog.FindAll();

                Assert.IsNotNull(blogs);
                Assert.AreEqual(11, blogs.Count());

                blog.Delete();

                blogs = Blog.FindAll();

                Assert.IsNotNull(blogs);
                Assert.AreEqual(10, blogs.Count());
            }
        }
開發者ID:shosca,項目名稱:ActiveRecord,代碼行數:24,代碼來源:ActiveRecordTestCase.cs

示例3: LifecycleMethods

        public void LifecycleMethods()
        {
            using (new SessionScope()) {

                var blog = new Blog {Name = "hammett's blog", Author = "hamilton verissimo"};

                Assert.IsFalse(blog.OnSaveCalled());
                Assert.IsFalse(blog.OnDeleteCalled());
                Assert.IsFalse(blog.OnLoadCalled());
                Assert.IsFalse(blog.OnUpdateCalled());

                blog.Save();

                Assert.IsTrue(blog.OnSaveCalled());
                Assert.IsFalse(blog.OnDeleteCalled());
                Assert.IsFalse(blog.OnLoadCalled());
                Assert.IsFalse(blog.OnUpdateCalled());

                blog.Name = "hammett's blog x";
                blog.Author = "hamilton verissimo x";
                blog.Save();
                Assert.IsTrue(blog.OnUpdateCalled());
                blog.Evict();

                blog = Blog.Find(blog.Id);
                Assert.IsTrue(blog.OnLoadCalled());

                blog.Delete();
                Assert.IsTrue(blog.OnDeleteCalled());
            }
        }
開發者ID:shosca,項目名稱:ActiveRecord,代碼行數:31,代碼來源:ActiveRecordTestCase.cs

示例4: SessionScopeFlushModeNever

        public void SessionScopeFlushModeNever()
        {
            using (new SessionScope()) {
                Post.DeleteAll();
                Blog.DeleteAll();
            }

            using(var scope = new SessionScope(FlushAction.Never))
            {
                var blog = new Blog {Author = "hammett", Name = "some name"};

                //This gets flushed automatically because of the identity field
                blog.Save();

                var blogs = Blog.FindAll().ToArray();
                Assert.AreEqual(1, blogs.Length);

                //This change won't be saved to the db
                blog.Author = "A New Author";
                blog.Save(false);

                //The change should not be in the db
                blogs = Blog.FindAllByProperty("Author", "A New Author").ToArray();
                Assert.AreEqual(0, blogs.Length);

                scope.Flush();

                //The change should now be in the db
                blogs = Blog.FindAllByProperty("Author", "A New Author").ToArray();
                Assert.AreEqual(1, blogs.Length);

                //This change will be save to the db
                blog.Name = "A New Name";
                blog.Save();

                //The change should now be in the db
                blogs = Blog.FindAllByProperty("Name", "A New Name").ToArray();
                Assert.AreEqual(1, blogs.Length);

                //This deletion should not get to the db
                blog.Delete(false);

                blogs = Blog.FindAll().ToArray();
                Assert.AreEqual(1, blogs.Length);

                scope.Flush();

                //The deletion should now be in the db
                blogs = Blog.FindAll().ToArray();
                Assert.AreEqual(0, blogs.Length);
            }
        }
開發者ID:shosca,項目名稱:ActiveRecord,代碼行數:52,代碼來源:SessionScopeTestCase.cs

示例5: MixingSessionScopeAndTransactionScopes3

        public void MixingSessionScopeAndTransactionScopes3()
        {
            var b = new Blog();

            using(new SessionScope())
            {
                b.Name = "a";
                b.Author = "x";
                b.Save();

                using(new TransactionScope())
                {
                    for(var i = 1; i <= 10; i++)
                    {
                        var post = new Post(b, "t", "c", "General");
                        post.Save();
                    }
                }
            }

            using(new SessionScope())
            {
                // We should load this outside the transaction scope

                b = Blog.Find(b.Id);

                using(var transaction = new TransactionScope())
                {
                    if (b.Posts.Count > 0)
                        foreach(var p in b.Posts)
                        {
                            p.Delete();
                        }

                    b.Delete();

                    transaction.VoteRollBack();
                }
            }

            using (new SessionScope()) {
                var blogs = Blog.FindAll().ToArray();
                Assert.AreEqual(1, blogs.Length);

                var posts = Post.FindAll().ToArray();
                Assert.AreEqual(10, posts.Length);
            }
        }
開發者ID:shosca,項目名稱:ActiveRecord,代碼行數:48,代碼來源:TransactionScopeTestCase.cs


注:本文中的Blog.Delete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。