当前位置: 首页>>代码示例>>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;未经允许,请勿转载。