Special Name

In DbEntry, we can define special name CreatedOn and UpdatedOn. So when we insert it, the CreatedOn column will set as current time. When we update it, the UpdatedOn column will set as current time.

public class DateTable : DbObjectModel<DateTable>
{
    public string Name { get; set; }

    [SpecialName]
    public DateTime CreatedOn { get; set; }

    [SpecialName]
    public DateTime? UpdatedOn { get; set; }
}

The name of them must be CreatedOn or UpdatedOn and the type must be DateTime. And UpdatedOn must be nullable.

The name(s) in our code can’t change. But the mapped name could define as another name:

public class DeletedUser : DbObjectModel<DeletedUser>
{
    [SpecialName, DbColumn("DeletedOn")]
    public DateTime CreatedOn { get; set; }
}

There is another special name LockVersion. We can use it for optimistic locking:

public class TestTable : DbObjectModel<TestTable>
{
    [SpecialName]
    public int LockVersion { get; set; }
}

When we updata the record, the LockVersion will be checked and increased. If update statement can't find any matched record, an exception will be raised.

The name of LockVersion in our code can’t change. But the mapped name could define as another name:

public class TestTable : DbObjectModel<TestTable>
{
    [SpecialName, DbColumn("TestVersion")]
    public int LockVersion { get; set; }
}

SavedOn

SavedOn works like compose of CreatedOn and Updated. When we insert or update the object, it all set as the current time.

public class DateTable : DbObjectModel<DateTable>
{
    [SpecialName]
    public DateTime SavedOn { get; set; }
}

If we need map it as another name in database, the DbColumn attribute could help us.

Count

Count works as SQL "Count = Count + 1". When we need a counter of saved times, we can use it:

public class Test : DbObjectModel<Test>
{
    [SpecialName]
    public int Count { get; set; }
}

If we need map it as another name in database, the DbColumn attribute could help us.

Last edited Apr 9, 2014 at 2:03 PM by lifeng, version 11

Comments

lifeng Dec 10, 2009 at 4:28 AM 
tobig5:
在最新源码里已经修正,谢谢。

tobig5 Oct 24, 2009 at 7:10 AM 
特殊字段为日期的时候在ACCESS下有问题

应该是获取日期的时候错误的使用了GETDATE(),应该使用NOW()吧。