With the interceptor you can:

public class MyInterceptor : EmptyInterceptor
{
 public override bool OnFlushDirty(object entity, object id, object[]
currentState, object[] previousState, string[] propertyNames, IType[]
types)
 {
    int md = FindProperty("ModifiedDate", propertyNames);
    if(md  >= 0)
       currentState[i] = DateTime.Now; //or via IoC
 }

public override bool OnSave(object entity, object id, object[] state,
string[] propertyNames, IType[] types)
{
   int md = FindProperty("CreatedDate", propertyNames);
    if(md  >= 0)
       state[i] = DateTime.Now; //or via IoC

}

         private static int FindProperty(string property, string[] 
propertyNames)
                {
                        for (int i = 0; i < propertyNames.Length; i++)
                        {
                                if (propertyNames[i] == property)
                                        return i;
                        }
                        return -1;
                }
}

On Thu, Jan 22, 2009 at 7:09 AM, Nexus <[email protected]> wrote:
>
> Write interceptor it doesn't need a setter :)
>
> On 16 jan, 20:24, epitka <[email protected]> wrote:
>> How would one go about updating a ModifiedDate and CreatedDate columns
>> if I do not want to expose setters on my class. So when record is
>> being persisted it should NH should auto set these two properties to
>> Now() and so that ModifiedDate is always updated and CreatedDate only
>> when record is new. Is there a way to do that.
>>
>> I know I can write interceptors etc. but I do not want these to have
>> setters at all.
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to