-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: PONOs vs DataSet: About Nulls
PostPosted: Fri Jul 29, 2005 10:24 am 
Regular
Regular

Joined: Fri Jul 29, 2005 9:46 am
Posts: 101
Hi!
First of all, I have been evaluating NHibernate an I really like it
I found it really easy to use.. but maybe I am biased because used to be a user of the original Hibernate for Java ;).

Now... the only disadvantage I have found for NHiberate is that in .NET ints, datetimes, decimals, etc cannot be nulls... so our PONOs (Plain Old .NET Objects) cannot represent a commonly used "database value"

In a Typed DataSet, this is solved by adding "special" properties, that is if for example, there is a property:

Class Person{
public DateTime DateTime BirthDate{
get{}
set{}
}
}

That could be null, then the code generator generates an two extra methods

Class Person{
public DateTime DateTime BirthDate{
get{}
set{}
}

public bool IsBirthDateNull() {
}

public void SetBirthDateNull() {
}
}

So, if I want to check in BirthDate is null, a first go an check if there is a property method named Is[NullablePropertyName]Null, and if is true, it means the database has a null. And If I want to set it as null all I have to do is use the "Set" method.

Now, this pair of method sounds a lot like a property, so it could be generated as:

public bool IsBirthDateNull{
get{}
set{}
}

IMHO this could permit handling nulls without using nullable types... so... my question is... in which files should do you recommend I start hacking to add this "feature"? do you think it is good idea?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 9:52 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
IMHO, it will not be easy to add this feature...

Why don't you want to use Nullable Types?

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 7:48 pm 
Beginner
Beginner

Joined: Wed Jun 29, 2005 10:40 am
Posts: 30
Location: denver, co
Just use the NullableTypes. You could be confused - the NullableTypes can't actually be set to null. They provide a "HasValue" property, which does the same thing as your IsBirthDateNull() function.

Here is an implementation of what you want using the NullableTypes:

Code:
Class Person{

  private NullableDateTime birthDate;
  public DateTime BirthDate{
    get{ return this.birthDate.Value;}
    set{ this.birthDate = value;}
  }

  internal NullableDateTime NullableBirthDate
  {
    get{ return this.birthDate; }
    set{ this.birthDate = value; }
  }

  public bool IsBirthDateNull()
  {
     return !this.birthDate.HasValue;
  }


The mapping for this class would then look like this:

Code:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="Namespace.Person, Assembly" table="PersonTable">
      <id name="Id" type="Int32" unsaved-value="0" column="PersonId">
         <generator class="native" />
      </id>
      <property name="NullableBirthDate" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" column="BirthDateColumn"/>
   </class>
</hibernate-mapping>



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.