Default values for new class attributes

Thread is closed for posting
2 posts, 0 answers
  1. Saene
    Saene avatar
    13 posts
    Member since:
    Sep 2008

    Posted 14 Apr 2009 Link to this post


    I just wonder how to specify a default value for new attributes added to existing class.

    Imagine, a class holding a number and a string (version 1).

    In version 2, I want to add a bool value to this class, but I don't want the existing records to be updated with the boolean default value.

    I use the VSchema to update my customers databases, so that I don't have to deliver the sql script.

    Any idea?


  2. Alexander
    Alexander avatar
    727 posts

    Posted 15 Apr 2009 Link to this post

    Hello Saene,

    You can use nullable boolean (bool?) field. Then the old records in the database will get a NULL value in that column instead of a zero. This way you will be able to distinguish between records from version 1 and 2. If you do not want to use nullables, you can create a custom script and have a table column that allows nulls (so the old records will have null there), but in that case the loaded objects will have value false instead of NULL. I think it is better to use nullable booleans.

    Kind regards,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top