Initializing a backing field shouldn't make much of a difference
compared to having it in the constructor right?

If Start = DateTime.MaxValue; is a typical example of the kind of code
you are referring to, my suggestion is to stop worrying. You could
profile it of course, but I would be surprised if you can get any
noticable gain from avoiding that code when NHibernate is
instantiating the object. Query time, database latency, and everything
else NHibernate has to do is likely to far outweigh such simple
constructor code.

/Oskar


2011/2/21 sturdytree <[email protected]>:
> 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.
>
>

-- 
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