This is a migrated thread and some comments may be shown as answers.

Default values for new class attributes

1 Answer 74 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Saene
Top achievements
Rank 1
Saene asked on 14 Apr 2009, 01:32 PM
Hi,

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?

Thanks,

Antoine.

1 Answer, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 15 Apr 2009, 11:45 AM
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,
Alexander
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.
Tags
General Discussions
Asked by
Saene
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or