Tigraine

Daniel Hoelbling-Inzko talks about programming

Setting a InsertedOn Field with Castle ActiveRecord

Posted by Daniel Hölbling on May 26, 2009

If I want a field to contain the date of insertion I’d usually have to hook into the Create method somewhere be it my repository or whatever.
With Castle ActiveRecord it’s as simple as overriding the Create() method in your Entity:

[ActiveRecord]
public class Comment : ActiveRecordBase<Comment>
{
    [PrimaryKey]
    public long Id { get; set; }
    [Property]
    public DateTime CreatedOn { get; set; }
    [Property]
    public string Message { get; set; }
    private void SetInsertionTimestamp()
    {
        CreatedOn = DateTime.Now;
    }
    public override void Create()
    {
        SetInsertionTimestamp();
        base.Create();
    }
    public override void CreateAndFlush()
    {
        SetInsertionTimestamp();
        base.CreateAndFlush();
    }
}

Filed under net, castle, programmierung
comments powered by Disqus

My Photography business

Projects

dynamic css for .NET

Archives

more