In order for this to work you define a method on the object (private or public dont matter) with no arguments, In this Example I am do a 'Calculation'. The function will be called after the object is initialized from the data store

Uisng the AdditionalInit Attribute

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess.Core.Attributes;

namespace SauceExample
{
  public class MyObject
  {
    public int id { get; set; }

    [DataField(DefaultValue="Bob")]
    public string Name { get; set; }

    [IgnoredField]
    public int Length { get; set; }
    
    [AdditionalInit]
    public void CallMeWhenLoaded()
    {
      Length = Name.Length;
    }
  }
}

Starting in v 1.4 you can also specify a constructor

The only requirement is the parms on the constructors must match the names of the target properties (case insensitive). You are not required to accept every property has a parameter. If you remap the column as I have below name the argument that

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess.Core.Attributes;

namespace SauceExample
{
  public class MyObject
  {
    public MyObject()
    {

     }

    public MyObject(string Bob, int id)
    {
        this.id = id;
        this.Name = Bob;
        Length = this.Name.Length;
    }
    public int id { get; set; }

    [DataField(DefaultValue="Bob")]
    public string Name { get; set; }

    [IgnoredField]
    public int Length { get; set; }
  }
}


Starting with Version 1.4.1 Additonal Init can accept IDataStore
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess.Core.Attributes;

namespace SauceExample
{
  public class MyObject
  {
    public int id { get; set; }

    [DataField(DefaultValue="Bob")]
    public string Name { get; set; }

    [IgnoredField]
    public int Length { get; set; }
    
    [AdditionalInit]
    public void CallMeWhenLoaded(IDataStore foo)
    {
       //foo is the dstore that loaded the object
       //do whatever with it
    }
  }
}

Last edited May 30, 2013 at 3:17 AM by iamkrillin, version 7

Comments

No comments yet.