I have a mapped class along following lines:
public class SomeClass
{
public DateTime Start { get; set; }
public SomeClass()
{
Start = DateTime.MaxValue;
}
}
I want to initialise Start when creating the class in code.
NHibernate calls the constructor when creating retrieved entities, and
so sets Start to it's default value, but I assume it then sets Start
to the retrieved value so the hydrated entity ends up with correct
value.
My question is whether there is a more elegant way to do this (running
unnecessary code is not ideal).
I could have a constructor like:
public SomeClass(DateTime date)
{
Start = date;
}
but then I do not want to create the class in code using following as
it is not intuitive:
SomeClass c = new SomeClass(DateTime.MaxValue);
I suppose I could also create a backing field and initialise that, so
leaving constructor empty, but I want to see if there is a way to keep
the automatic property.
--
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.