Soft Delete

In DbEntry, we can define the class as soft delete. It means there is a column named "IsDeleted" would be used to judge is the row deleted or not.

[SoftDelete]
public class User : DbObjectModel<User>
{
    public string Name { get; set; }
}

This class maps to a table which has a column "IsDeleted" with bool type.

We can define another name to this column:

[SoftDelete(ColumnName = "IsDel")]
public class User : DbObjectModel<User>
{
    public string Name { get; set; }
}

Now, we can use it in our code:

User o = User.FindById(1);
o.Name = "test";
o.Save();

o = User.New;
o.Name = "tt";
o.Save();

o.Delete();

Attention: the cross-table of many to many relations doesn’t support soft delete. This table is automatically use and always use the real delete.

Last edited Apr 9, 2014 at 3:04 PM by lifeng, version 8

Comments

lifeng Dec 10, 2009 at 5:42 AM 
@tobig5
不知道你用的哪个版本,我在最新源代码上加了这个单元测试,没发现问题。
另外,建议把问题发到Discussions里,wiki里的comments我一般不会检查,所以可能很久我都不知道有这个comment。

tobig5 Oct 24, 2009 at 8:08 AM 
使用软删除的时候有问题。

运行下面的代码两条数据都会被删除

User u = User.New().Init("test11","0001","0001", 22, false, DateTime.Now);
u.Name = "test22";
u.Save();

User u2 = User.New();
u2.Name = "new111111111";
u2.Save();

u2.Delete();