The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Non Nullbale column still gets a Nullable Property

Last post 08-11-2008, 2:39 PM by robert.wachtel. 17 replies.
Page 1 of 2 (18 items)   1 2 Next >
Sort Posts: Previous Next
  •  05-21-2007, 1:50 AM 2553

    Non Nullbale column still gets a Nullable Property

    Hi,

    I'm just running the code gen template c# Master Generated and noticed that even if a column is not Nullable, a Nullable property is generated.
    Is this correct?

    Cheers,

    John

  •  05-21-2007, 2:25 AM 2554 in reply to 2553

    Re: Non Nullbale column still gets a Nullable Property

    EntitySpaces will always generate a nullable type if one is available in .NET. This is done regardless of whether the database schema is flagged NOT NULL for that column. There is an item on our tracking list to change this, but there is some debate as to whether or not it would be confusing to have to know how a column is flagged in the database before you can use it. For now, it will always be a nullable type.
    David Neal Parsons
    www.entityspaces.net
  •  08-04-2007, 7:09 AM 4305 in reply to 2554

    Re: Non Nullbale column still gets a Nullable Property

    Just to register my vote, when I have a table with required primitive fields, so I know there'll always be a value there, having to constantly cast or .Value the member is a real pain.  Seems intuitive to me that if the DB field is not nullable, then the member should not be nullable.  Intellisense will show you immediately if the member is nullable or not, so the programmer does not need to know anything about the DB schema before hand.

     It should at least be an option in the code gen.  You can always default it to everything nullable for backwards compatibility/convention.

     Thanks,

    John K.

     

  •  02-07-2008, 7:50 PM 7938 in reply to 2554

    Re: Non Nullbale column still gets a Nullable Property

    I also vote for having EntitySpaces not generate nullable properties if the db field is not nullable.

     Steve O.

  •  02-07-2008, 8:16 PM 7941 in reply to 7938

    Re: Non Nullbale column still gets a Nullable Property

    There is a template in the "esPlugIn" folder in the EntitySpaces folder in MyGeneration called "EntitySpaces - Set esPlugin Settings". If you run that there is a checkbox titled "Use Nullable Types Always". You can uncheck that and click Ok. Currently this is experimental, I did some testing and it did work, you might flip it and regenerate and see how it works. Hopefully for ES2008 we can officially sanction that checkbox, however, I do remember doing a full generation with it and things seemed to work, but we cannot guarantee that yet.

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  02-07-2008, 8:34 PM 7944 in reply to 7941

    Re: Non Nullbale column still gets a Nullable Property

    Thank you,

    I tested it in my little test project, and it works the way I wanted it to work.

    Steve

  •  08-11-2008, 5:07 AM 10664 in reply to 7944

    Re: Non Nullbale column still gets a Nullable Property

    Just tested it with the newest maintenance release (with the last MyGeneration release) and for me it does not work as expected.

    I have a table (T_Validator) in Oracle 10g

    ID         Number 15,0 primary key
    IsValid   Number 1,0 non-nullable

    The generated proxy stub looks like

    Code:
            public System.Decimal Id
    {
    get
    {
    if (this.Entity.es.IsDeleted)
    return (System.Decimal)this.Entity.
    GetOriginalColumnValue(TValidatorMetadata.ColumnNames.Id);
    else
    return this
    .Entity.Id;
    }
    set { this.Entity.Id = value; }
    }

    public System.Decimal IsValid
    {
    get
    {

    if (this.IncludeColumn(TValidatorMetadata.ColumnNames.IsValid))
    return this.Entity.IsValid;
    else
    return null
    ;
    }
    set { this.Entity.IsValid= value; }
    }
    So the type System.Decimal was generated correctly, but the code tries to assign a null value to a non-nullable field.

    Any ideas?

    Greetings from Cologne

    Robert

    http://blog.robertsoft.de/
    Filed under:
  •  08-11-2008, 6:18 AM 10666 in reply to 10664

    Re: Non Nullbale column still gets a Nullable Property

    Hi Robert

    The code you've posted above (from the proxy class) isn't anything to do with setting the property - whether it's to null or not.  Basically you have a choice as to whether you want to include a property or not in the proxy (i.e. you might only want the proxy/xml to include chaged properties instead of all properties) - the check (and return of null) looks to see if this field/property should be included in the proxy being returned - if so, it returns it, if it shouldn't be included, it returns null - does that make sense?

    Cheers

    Martin

  •  08-11-2008, 6:32 AM 10669 in reply to 10666

    Re: Non Nullbale column still gets a Nullable Property

    Hi Martin,

    the problem is that the generated code isn't even compilable.

    Let's have a look again:

    Code:
    1    public System.Decimal IsValid
    2 {
    3 get
    4 {
    5 if (this.IncludeColumn(TValidatorMetadata.ColumnNames.IsValid))
    6 return this.Entity.IsValid;
    7 else
    8 return null
    ;
    9 }
    10 set { this.Entity.IsValid= value; }
    11 }

    IsValid is a non-nullable property of type System.Decimal. But in line 8 (the null-assignment) the return value is not compatible with the type definition of the property.

    Since this is auto-generated code something seems to be not correct... Wink


    Greetings from Cologne

    Robert

    http://blog.robertsoft.de/
  •  08-11-2008, 6:39 AM 10670 in reply to 10669

    Re: Non Nullbale column still gets a Nullable Property

    This is a little confusing because you hi-jacked an existing thread (frowned upon Sad) and it wasn't even really related. However, when you generated your classes did you check the special flag in the Settings template concerning nullable fields?
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-11-2008, 6:49 AM 10673 in reply to 10670

    Re: Non Nullbale column still gets a Nullable Property

    Mike.Griffin:
    This is a little confusing because you hi-jacked an existing thread (frowned upon Sad) and it wasn't even really related.

    Isn't it really?

    Since this thread was already hijacked in February w/o any comment from you I thought this was ok. Anyway, next time I will open new threads.

    However, when you generated your classes did you check the special flag in the Settings template concerning nullable fields?

    Yes, of course. See, if I do not check the special flag the code generated is as following (and works - but in the database table the field is non-nullable):

     Code:

    public System.Decimal? IsValid
    {
    get
    {
    if (this.IncludeColumn(TValidatorMetadata.ColumnNames.IsValid))
    return this.Entity.IsValid;
    else
    return null
    ;
    }
    set { this.Entity.IsValid= value; }
    }

     

    With the flag checked the generated code is not compilable:

    Code:
    public System.Decimal IsValid
    {
    get
    {
    if (this.IncludeColumn(TValidatorMetadata.ColumnNames.IsValid))
    return this.Entity.IsValid;
    else
    return null
    ;
    }
    set { this.Entity.IsValid= value; }
    }


    Greetings from Cologne

    Robert

    http://blog.robertsoft.de/
  •  08-11-2008, 7:31 AM 10676 in reply to 10673

    Re: Non Nullbale column still gets a Nullable Property

    Hi

    I think what would need to happen here is that the "Generated - ProxyStub - (C#).cst" templates need changing around the property setter to see whether the user has chosen the "UseNullableTypesAlways" setting - if so then write output as it does currently, if not then just skip the "if (this.IncludeColumn(.....)" test and just return the property regardless - shouldn't take much in the way of changes to the template to be honest, not from what I can see at first glance anyway

    Hope that helps

    Martin

  •  08-11-2008, 7:36 AM 10677 in reply to 10676

    Re: Non Nullbale column still gets a Nullable Property

    Hi Martin,

    thanks for your reply. I'm a new user of EntitySpaces (since a week) and therefore not that deeply involved. I'll see if I can dig into modifying the template... Wink

    Thanks again!


    Greetings from Cologne

    Robert

    http://blog.robertsoft.de/
  •  08-11-2008, 7:41 AM 10679 in reply to 10676

    Re: Non Nullbale column still gets a Nullable Property

    Thanx Robert (and Martin). When we added the "Use Nullable Types Always" flag it was kind of experimental. The proxy templates have not been updated to account for that feature. I will bump this up on our list for our next maintenance release. We used to have a big warning on the "Use Nullable Types Always" flag but looks like we removed it. As an FYI, proxies are key to ES2009 and will be receiving much attention. We will bump this in our priority.

     


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-11-2008, 7:47 AM 10680 in reply to 10679

    Re: Non Nullbale column still gets a Nullable Property

    In the meantime Robert, if you need any help on altering the templates until the official fix/alteration is in then post up which templates you're using (MyGen or CodeSmith) and I'm sure either myself or one of the EntitySpaces team can help in making the correction

    Cheers

    Martin

Page 1 of 2 (18 items)   1 2 Next >
View as RSS news feed in XML