use a field that will get the data, and a property that in its get method,
checks if the field is null and if so, returns the default

On Sat, May 8, 2010 at 1:12 AM, Dathan <[email protected]> wrote:

> Hi, all.
>
> I'm trying to strengthen my domain by eliminating null in favor of
> "Null" objects with explicit semantics.  E.g.,
>
> class Category
> {
>    private static Category @default;
>
>    static Category()
>    {
>        // init @default here
>    }
>
>    public virtual int ID { get; set; }
>    public virtual string Name { get; set; }
>    public virtual Category Parent { get; set; }
>    public static Category None { get { return @default; } }
> }
>
> My categories support nesting (hence the Parent property), but top-
> level categories won't have parents.  I'd like to represent this in my
> model by having the category's Parent set to Category.None.  My
> question is, in terms of NHibernate, what's the best way to map this?
> Should I have a category record in my database called None with a null
> ParentID, and have all "top-level categories" store that ID as their
> parent?  Or, should I serialize all references to Category.None as
> NULL categoryID's, and replace all NULL CategoryID's with
> Category.None upon retrieval?  (If so, how?)  What's the best practice
> here?
>
> Thanks!
>
> ~Dathan
>
> --
> 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]<nhusers%[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