Converting from 1.1 to 2.6 Question - nullable plugin

Posts   
 
    
IowaDave
User
Posts: 83
Joined: 02-Jun-2004
# Posted on: 29-Jul-2009 16:25:13   

In going to 2.6 from 1.0.2004.2

I have run the plugin to 'Set all 'Generate as Nullable type' flags to false.

And I set the Project Property ConvertNulledReferenceTypesToDefaultValue = true

I would expect ExportControlFormulaDefNumber to be set to 0 when the database column is null, as it did in the older release.

Here is the generated code from both old and new versions for the ExportControlFormulaDefNumber property.


//  generated code from 2.6 
    /// <remarks>Mapped on  table field: "ExportTypeDef"."ExportControlFormulaDefNumber"<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 ExportControlFormulaDefNumber
        {
            get { return (System.Int32)GetValue((int)ExportTypeDefFieldIndex.ExportControlFormulaDefNumber, true); }
            set { SetValue((int)ExportTypeDefFieldIndex.ExportControlFormulaDefNumber, value); }






        }


// generated code from 1.0.2004.2
        /// <summary>
        /// The ExportControlFormulaDefNumber property of the Entity ExportTypeDef<br/><br/>
        /// 
        /// </summary>
        /// <remarks>
        /// Mapped on  Table field: "ExportTypeDef"."ExportControlFormulaDefNumber"<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 ExportControlFormulaDefNumber
        {
            get
            {
                object valueToReturn = base.GetCurrentFieldValue((int)ExportTypeDefFieldIndex.ExportControlFormulaDefNumber);
                if(valueToReturn == null)
                {
                    valueToReturn = TypeDefaultValue.GetDefaultValue(typeof(System.Int32));
                }
                return (System.Int32)valueToReturn;
            }
            set
            {
                if(SetNewFieldValue((int)ExportTypeDefFieldIndex.ExportControlFormulaDefNumber, value))
                {
                    OnExportControlFormulaDefNumberChanged();
                }
            }
        }


Thanks, Dave

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 29-Jul-2009 17:15:31   

It should return the default value of the field type. Please note that int is not a reference type.

Would you please attach the lgp project, and point me to the mentioned entity.

IowaDave
User
Posts: 83
Joined: 02-Jun-2004
# Posted on: 29-Jul-2009 17:29:35   

See attached project

The entity is ExportTypeDef

IowaDave
User
Posts: 83
Joined: 02-Jun-2004
# Posted on: 29-Jul-2009 17:45:31   

Can't tell if you got the attachment. It is 4.5 mb. Do I need to create a smaller project or can you allow it to upload?

Dave

IowaDave
User
Posts: 83
Joined: 02-Jun-2004
# Posted on: 29-Jul-2009 21:52:53   

I think I found what is happening. The code that was using the entity class was addressing the data like this:

// Technique #1 m_exportcontrol = Int32.Parse (exportDefEntity.Fields["ExportControlFormulaDefNumber"].CurrentValue.ToString());

which returned the null value.

However, if we do this

// technique #2 m_exportcontrol = Int32.Parse (exportDefEntity.ExportControlFormulaDefNumber.ToString());

we get the default value for int, which, of course, is 0

So the question remains: why did it work in older versions with Technique #1?

Thanks,

Dave

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Jul-2009 06:21:34   

What .Net framework version are you using? SelfServicing or Adapter? This link would be helpful: NULL values and Defaults.

David Elizondo | LLBLGen Support Team
IowaDave
User
Posts: 83
Joined: 02-Jun-2004
# Posted on: 30-Jul-2009 17:26:14   

I'm using .Net Framework 3.0 and Adapter

I'm going with the idea now that as long as we reference the entity's properties like this: var = entityName.ColumnName ; it will work (i.e. the null value will be replaced with 0)

However, the other way of getting the value var = entityName.Fields["ExportControlFormulaDefNumber"].CurrentValue; returns the null value.

My inquiry at this point is - should this have changed between releases? With the previous release, both methods would return a 0. With the current release, only the first technique ( var = entityName.ColumnName ; ) returns the 0.

IowaDave
User
Posts: 83
Joined: 02-Jun-2004
# Posted on: 31-Jul-2009 00:19:19   

I see this thread was marked as done.

I had an outstanding question in my last post. If anyone knows why this behaves differently in 2.6, could you share that? (see previous message).

Thanks

Dave

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 31-Jul-2009 11:04:10   
IowaDave
User
Posts: 83
Joined: 02-Jun-2004
# Posted on: 31-Jul-2009 15:24:29   

Thanks for the info. I can now give a reason to our programmers to change to using the properties.

Dave