本文整理汇总了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);
}
示例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());
}
}
示例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());
}
}
示例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);
}
}
示例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);
}
}