Question on dealing with Null Values in version 2.6 vs 1.0

Posts   
 
    
IowaDave
User
Posts: 83
Joined: 02-Jun-2004
# Posted on: 28-Oct-2008 14:59:00   

Note: I moved this from a reply to another thread on the architecture forum. I thought it belonged here. Sorry for the multiple post, but I also hadn't gotten any replies.

Please help me understand what my options are.

I'm attempting to migrate to 2.6 from 1.0.2004.2 Final August 5, 2005 version.

In version 1, I'm getting this behavior: if a null is in the database on an int column, I get a 0 back when I say clientClass.myint = entityClass.myint; In my migration tests though, I get back a null, and of course .Net throws an exception when I execute the assignment.

My question is: how do I get 2.6 to behave the same as 1.0.2004.2 in regards to nulls? I've read the documentation and I don't see where the new version allows this.

Do I need to change the templates?

Thanks

Dave

Fab
User
Posts: 108
Joined: 20-Oct-2008
# Posted on: 28-Oct-2008 19:01:49   

I'm just finishing my upgrade from an 2005 version to the lastest so I can help you You have 2 options 1) I've not tested : you can change in the designer to not generate nullable type for the nullable field. I'm almost sure there is also a plugin that allow you to update all entity & all fields to disable the generation of nullable type. Personally, I don't like this options as nullable type are great functinalities and it's easy to handle nullable fieds with nullable type.

2) change in you code to test each operation you're doing with nullable fields. I've do that in my project, it took time but now it works well. A nice tips for that is the coalesc operator : http://spinningtheweb.blogspot.com/2006/09/c-coalesce-operator.html In your example your code must be changed into :

clientClass.myint = entityClass.myint ?? 0;

Change the "0" by the value that was put by default when a null value was found in the db (in the old llblgen version). I think it was 0 in the generated class.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 28-Oct-2008 22:01:31   

As Fab has stated the way to duplicate this behavior in 2.x is to clear the tick box "(.Net 2.0+) Generate as nullable type" against each nullable field in the designer.

The plugin to automatically set/toggle all of these check boxes is available under Tools -> PlugIns as part of the standard installaton.

Matt

IowaDave
User
Posts: 83
Joined: 02-Jun-2004
# Posted on: 28-Oct-2008 22:40:29   

As Fab has stated the way to duplicate this behavior in 2.x is to clear the tick box "(.Net 2.0+) Generate as nullable type" against each nullable field in the designer.

The plugin to automatically set/toggle all of these check boxes is available under Tools -> PlugIns as part of the standard installaton.

I have tried this but I'm not getting the behavior I got in 1.0. In 1.0, it would return the default for the type (eg. int32 would return a 0. a boolean would be false) if the data was a null. but with 2.6 I am getting a null object returned. Am I doing something wrong (putting aside the way we are allowing nulls in the database)?

Here is what is being generated.


        /// <summary> The DollarFields property of the Entity Company<br/><br/>
        /// </summary>
        /// <remarks>Mapped on  table field: "Company"."DollarFields"<br/>
        /// Table field type characteristics (type, precision, scale, length): Int, 10, 0, 0<br/>
        /// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
        public virtual System.Int32 DollarFields
        {
            get { return (System.Int32)GetValue((int)CompanyFieldIndex.DollarFields, true); }
            set { SetValue((int)CompanyFieldIndex.DollarFields, value); }
        }
        /// <summary> The IsAllowShowHiddenCues property of the Entity Company<br/><br/>
        /// </summary>
        /// <remarks>Mapped on  table field: "Company"."IsAllowShowHiddenCues"<br/>
        /// Table field type characteristics (type, precision, scale, length): Bit, 0, 0, 0<br/>
        /// Table field behavior characteristics (is nullable, is PK, is identity): true, false, false</remarks>
        public virtual System.Boolean IsAllowShowHiddenCues
        {
            get { return (System.Boolean)GetValue((int)CompanyFieldIndex.IsAllowShowHiddenCues, true); }
            set { SetValue((int)CompanyFieldIndex.IsAllowShowHiddenCues, value); }
        }


MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 28-Oct-2008 22:56:36   

Interesting, my sample works exactly as you want it to - the default value of a nullable int column with the checkbox un-ticked returns 0

Can you check that the code goes through HelperClasses.TypeDefaultValue.GetDefaultValue ?

Have you tried deleting all of the generated code before re-generating in order to ensure that you are using the generated version (code being read-only can prevent generation working correctly)

I am using 2.6 Final

Matt

IowaDave
User
Posts: 83
Joined: 02-Jun-2004
# Posted on: 28-Oct-2008 23:06:02   

Thanks, I'll try from a clean work area.

Do I also need to change the order of the template sets or is that not needed?

Thank again.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 28-Oct-2008 23:12:41   

IowaDave wrote:

Do I also need to change the order of the template sets or is that not needed?

You shouldn't need to, my test was with a standard 2.6 install.

hedecan
User
Posts: 1
Joined: 17-Nov-2009
# Posted on: 17-Nov-2009 09:53:34   

migrated from 1.0 to 2.6

i must change to code for nullable types ?

tnx

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 17-Nov-2009 10:39:18   

Dear hedecan, please don't re-open old threads, create new one instead.

Anyway, it's not clear what's your problem is and what's required. So I can't tell you to use nullable Types or not.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39863
Joined: 17-Aug-2003
# Posted on: 17-Nov-2009 16:48:50   

Also asked via email and answered via email. He used the plugin to set all GenerateAsNullableOfT flags to false to get it fixed.

Frans Bouma | Lead developer LLBLGen Pro