I'm wondering how to persist a property that depends on both regular persisted properties (e.g. string, int) as well as some custom transforms of their own.
For instance suppose I have
class A
{
public int Id {get; set;}
public string SomeString {get; set;}
public object SpecialProperty {get; set;}
}
suppose that persisting SpecialProperty requires reading SomeString and depending on it's value, producing some byte[] which can then be stored in the database.
My first thought was to use an IUserType, but this the method NullSafeGet(IDataReader rs, string[] names, object owner) is invoked before (or actually, during) SomeString is persisted (or not), so it is not set.
My second thought was to use a ICompositeUserType and some rather convoluted setup using wrappers.
My third thought was maybe I could implement ILifecycle and hook the OnLoad() method. But if I wanted to do that I would need to create a seperate property for the byte[] payload which I don't really want to store. This certainly seems the easiest to implement but also somewhat inelegant.
e.g.
class A : ILifecycle
{
public int Id {get; set;}
public string SomeString {get; set;}
public object SpecialProperty {get; set;}
private byte[] payloadData { get; set; }
public void OnLoad(ISession s, object id)
{
SpecialProperty = customIn(SomeString, payloadData);
payloadData = null;
}
static object customIn(string a, byte[] payload)
{
// ...
}
}
Does anybody know of an an easier and possibly more concise way?