Ah, I get it.  I didn't realize you could map fields in NHibernate.
But since fields can't be virtual, how does that affect lazy-loading
of the type?

~Dathan

On May 14, 2:04 am, nadav s <[email protected]> wrote:
> my suggestion was to map the field - then the field gets a null but the
> public property returns the "NULL object".
> same goes for the set of the public property - if it got the "Null object"
> it puts actual null in the field
>
>
>
>
>
> On Thu, May 13, 2010 at 2:03 PM, John Davidson <[email protected]> wrote:
> > You can create a base class for all your mapped objects with a must inherit
> > requirement. That allows you to create a single implementation and then
> > reuse it (DRY).
>
> > John Davidson
>
> > On Thu, May 13, 2010 at 3:25 AM, Dathan <[email protected]> wrote:
>
> >> That seem like it addresses the problem - because NHibernate reads the
> >> value from the property when saving, if the internally-stored value is
> >> null, the property will return my "NULL" value, and NHibernate will
> >> attempt to serialize that to the DB, rather than the NULL value that I
> >> actually want to store.
>
> >> It seems like a custom user type would fit the bill, because it
> >> supports NullSafeGet and NullSafeSet methods (sorry if I'm misstating
> >> the actual method names - the idea is right, though, right?).  Using
> >> that, I could override Equals() on each of my classes, and the
> >> UserType for the class would do something like "if (!
> >> obj.Equals(ObjectClassType.Null)) return obj else return null;".
> >> Would that work?  I'd prefer an approach that doesn't require me to
> >> implement a custom UserType per model class, though, so if there are
> >> any other options, I'm eager to hear them.
>
> >> Thanks!
>
> >> Dathan
>
> >> On May 7, 6:45 pm, nadav s <[email protected]> wrote:
> >> > 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]
> >> > >  >
> >> <nhusers%[email protected]<nhusers%252bunsubscr...@googlegroup
> >>  s.com>
>
> >> > > .
> >> > > 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]<nhusers%[email protected]
> >>  >
> >> .
> >> > For more options, visit this group athttp://
> >> 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]<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]<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 
> athttp://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