Note that there are some explanatory texts on larger screens.

plurals
  1. POpersisting a property that relies on other properties and custom transforms
    text
    copied!<p>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.</p> <p>For instance suppose I have</p> <pre><code>class A { public int Id {get; set;} public string SomeString {get; set;} public object SpecialProperty {get; set;} } </code></pre> <p>suppose that persisting SpecialProperty requires reading SomeString and depending on it's value, producing some byte[] which can then be stored in the database.</p> <p>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.</p> <p>My second thought was to use a ICompositeUserType and some rather convoluted setup using wrappers.</p> <p>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.</p> <p>e.g.</p> <pre><code>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) { // ... } } </code></pre> <p>Does anybody know of an an easier and possibly more concise way?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload