Telerik OpenAccess ORM – Default Values support has arrived

by OpenAccess ORM Team | Comments 4

As many of you already know, we are offering you a chance to choose which features of OpenAccess ORM you would like to see implemented in the next releases. You can post your votes and comments in our PITS system, plus you can ask us to put new features there through the support system or forums.

Recently there is one clear winner in PITS – the database default values support. It has been requested many times through our support system as well – and we would like to thank all of you for the feedback, we do appreciate it. We are glad to announce that this functionality is now in OpenAccess, and you can already have a look even before Q2 2012 by downloading our latest internal build (2012.1.427.1)!

What we have decided is that the columns containing default values will be marked with a Boolean flag, called HasDefaultValue.  This flag, stored in your Domain Model, basically means “skip this column from the insert statement unless the value is specified explicitly” when set to True. In other words when you are adding a new object, if the value in a nullable column is NULL, the column will be excluded from the insert statement. In case the column is not nullable, defining the property mapped to it as nullable will achieve the same result.

In case you don’t want to use the database default value, just set the HasDefaultValue flag to False and initialize the value in your code .

Since the internal build is just a preview of this new functionality, now is a perfect time to take a look and comment on our approach. Is anything missing? Is everything working as expected or the behavior is not intuitive for you? Do not hesitate to provide both your positive and negative feedback!

Download Free OpenAccess ORM Trial


Team Lead
Telerik OpenAccess ORM

4 Comments

Steve
Is this all DB driven, or can we SPECIFY the default value in the model itself, so when I create a new object in code I wouldn't have to add the property value?
Damyan
It is database-driven feature. During insert if a property has not value specified and the underlying column has default value constraint specified in the database, the column will be omitted from the generated statement. The default value generated from the server will be respected.
Damyan
Regarding the Model First approach – currently it is not possible to specify the default value and create the corresponding constraint on the database server. The default values are supported only in Database First scenarios when the default value constraint is already defined. We will consider support for default values with Model First approach in the future releases of the product, in case it is necessary. Do you prefer to create default value constraints in the database, or to specify the value in the constructor and why? We appreciate any feedback you might have for this matter.
Ian Yates
I'm a DB first guy - mainly because I have a legacy database (not poorly designed, just legacy) which our code will run against when we replace our old Delphi code with shiny new C# code.  The default value support is great for us.  I think if I was doing model-first, or code-first, I probably would just have the defaults in my code anyway and wouldn't expect the DB to do it.  Having said that, I like database first so it's hard for me to put the shoe on the other foot.
Keep up the great work with OA ORM :)    

Comments

  1.    
      
      
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)
Read more articles by OpenAccess ORM Team - or - read latest articles in Developer Tools
Product Families