TypedListRow and nullables

Posts   
 
    
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 25-Jan-2007 12:03:10   

Hi there,

Is there a particular reason that TypedListRow doesn't use nullables? Instead there are value-IsValueNull pairs as in strong typed datatable.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 25-Jan-2007 12:19:53   

datatable doesn't support Nullable<T> simple_smile

So the choice then was: add Nullable fields to the generated code or keep the original methods, and we decided to keep the original methods/properties so existing code was easier to upgrade.

Frans Bouma | Lead developer LLBLGen Pro
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 25-Jan-2007 13:15:49   

Hi otis,

Well, yes, I know that DataTable doesn't support nullables. However, I would prefere similar syntax:


public System.DateTime? Created 
        {
            get 
            {
                if(IsNull(_parent.CreatedColumn))
                {
                    return null;
                }
                else
                {
                    return (System.DateTime)this[_parent.CreatedColumn];
                }
            }
            set 
            {
                                                                if (value == null)
                                                                        value = DBNull.Value;
                this[_parent.CreatedColumn] = value;
            }
        }

over


public System.DateTime Created 
        {
            get 
            {
                if(IsCreatedNull())
                {
                    return (System.DateTime)TypeDefaultValue.GetDefaultValue(typeof(System.DateTime));
                }
                else
                {
                    return (System.DateTime)this[_parent.CreatedColumn];
                }
            }
            set 
            {
                this[_parent.CreatedColumn] = value;
            }
        }

        /// <summary>Returns true if the TypedList field Created is NULL, false otherwise.</summary>
        public bool IsCreatedNull() 
        {
            return IsNull(_parent.CreatedColumn);
        }

        /// <summary>Sets the TypedList field Created to NULL. Not recommended; a typed list should be used as a readonly object.</summary>
        public void SetCreatedNull() 
        {
            this[_parent.CreatedColumn] = System.Convert.DBNull;
        }

It isn't a big deal though.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 26-Jan-2007 11:12:49   

I prefer that too, though as I said, it's not possible, because you then have a problem upgrading: in the .NET 1.x code, these IsNull methods have to be there (no nullable types), so after a while you decide to upgrade from .NET 1.x to .NET 2.0, (your .NET 1.x code is made with llblgen pro v2.0 as well), and then you have a hard time, as the methods aren't there anymore. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
mihies avatar
mihies
User
Posts: 800
Joined: 29-Jan-2006
# Posted on: 26-Jan-2007 22:04:08   

Ok, backward compatibility. As an idea, you could provide both template versions, so once could pick the one required.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 28-Jan-2007 09:17:35   

mihies wrote:

Ok, backward compatibility. As an idea, you could provide both template versions, so once could pick the one required.

I could of course, but that wouldn't add something that valuable as it's a major breaking change, and maintaining another template just for this is IMHO not worth it.

Frans Bouma | Lead developer LLBLGen Pro