Setting default value for not-null columns

9 posts, 0 answers
  1. Bret
    Bret avatar
    14 posts
    Member since:
    May 2011

    Posted 29 Jun 2011 Link to this post

    Is there a way to specify a default value for columns which do NOT allow nulls using the designer? I have default values specified in my database schema for most of the fields in question. However, since they are specified as not-null, I cannot create a new instance of the object in question and save it without first specifying all of the not-null fields manually in C#. I haven't found a way, in the designer, to set default values for a field, and it doesn't look like the default values I already have specified in my database schema are being picked up.

    For the time being, I've been creating default constructors in my table objects and setting default values there, but if I have to do this for every table that currently uses defaults in the database it is going to take a significant amount of time. I'm also pretty certain this work would get blown away if I had to re-generate the model from my database for some reason. So, I'm wondering if there is a way, in the designer, to enter my default values, or if there is something I need to do to get OpenAccess to recognize the defaults already in my DB schema.


    - Bret
  2. Serge
    Serge avatar
    375 posts

    Posted 04 Jul 2011 Link to this post

    Hi Bret,

     Unfortunately at this time we do not provide such a functionality, we have planned for it however it will not make this release. What we actually would like to do is add a switch that would leave out inserts and updates on certain columns and leave the default generation to the database. 

    And yes, if you have had your changes in the code that is generated by the designer the next time you save the rlinq files they will be omitted. However you can create separate files with partial classes to the ones that we have generated for you that hold the default value logic. This way even if the classes are regenerated your code will not be lost.

    I hope this is helpful. 

    All the best,
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
  3. DevCraft banner
  4. Dan
    Dan avatar
    15 posts
    Member since:
    Mar 2006

    Posted 27 Feb 2013 Link to this post


    Is there a PITS for this?  I'd like to cast my vote for this functionality as well.
  5. Doroteya
    Doroteya avatar
    495 posts

    Posted 04 Mar 2013 Link to this post

    Hi Dan,

    Currently, Telerik OpenAccess ORM  supports database default values only for the Database First scenario (here is the documentation article about that feature).

    There is a post in our Ideas and Feedback portal regarding the extension of that feature, so that it is supported in the Model First scenario. This is the link.

    I hope that this is what you are looking for. If it is not or if you have other suggestions, do not hesitate to get back to us.


    the Telerik team
    OpenAccess ORM Q1 2013 is out featuring Multi-Diagrams, Persistent Data Stream Support and much more. Sign up for a free webinar to see all the new stuff in action.
  6. John
    John avatar
    16 posts
    Member since:
    Aug 2014

    Posted 22 Oct 2014 in reply to Doroteya Link to this post

    I'm facing a similar problem and have gotten a conflicting responses from the documentation ( and from the Telerik rep( 

    Although the columns are designated as having a default and are nullable both in the domain class and the schema's metacolumn, the run-time metadata of the same fields has default value indication as false and the insert statement that's generated has all the fields listed with DBNull for the value. I would appreciate an answer on whether this feature is functional and may be some direction of how to make it work, if it is.

    Regards, John
  7. Doroteya
    Doroteya avatar
    495 posts

    Posted 23 Oct 2014 Link to this post

    Hello John,

    I am sorry for both the misleading information in the referred forum thread, and the confusion you experienced.

    Let me confirm that the feature is functional, the tutorial in the documentation is correct, and that the settings you applied (according to the description in the referred forum thread) are correct.

    The behaviour you observe usually happens when an application is started without explicitly saving the domain model (the .rlinq file) first. On the Data Access side, saving the model is necessary, because it triggers our code generation functionalities, and they take care to preserve the new settings. In this connection, I suggest to you the following:

    1. Open the .rlinq file in Visual Designer.
    2. Move a class from one place to another on the diagram (in order to make a dummy change).
    3. When the asterisk sign (*) next to the name of the model appears, save the model.
    4. Run your application for a test.

    I hope this helps. Do let us know about the outcome on your side, after applying the suggested workflow.

    I am looking forward to your feedback.

    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
  8. John
    John avatar
    16 posts
    Member since:
    Aug 2014

    Posted 23 Oct 2014 in reply to Doroteya Link to this post

    Unfortunately, that didn't work.
    This is the appropriate portion of the rlinq file:
    Table definition:
          <orm:table name="D3_CALBlock">
            <orm:column name="VFCASC" sql-type="bit" nullable="true" length="0" scale="0" has-default-value="true" ado-type="Bit" />
    Domain class definition:
        <DomainClass Id="7e6f56e0-4d4d-477f-9fb4-de69c98be42a" name="D3_CALBlock" namespace="Novatech.ApplicationFramework.CDBService.Contracts" showPropertiesCompartment="true" identityMechanism="DatabaseServerCalculated" concurrencyMode="Changed" updateSchema="true" showNavigationCompartment="true" showImplementationCompartment="true" identityMechanismMember="Id">
     <Property Id="b9852ec5-208a-4296-a2c7-d5713ace1c37" name="VFCASC" type="Boolean" label="VFCASC : Boolean" nullable="true" kind="Persistent" fieldName="_vFCASC" />

    Class definition:
       <orm:class name="D3_CALBlock" update-schema="true" uniqueId="7e6f56e0-4d4d-477f-9fb4-de69c98be42a">
            <orm:table name="D3_CALBlock" />
              <orm:key-generator name="autoinc">
                <orm:key-generator-member property-name="Id" />
              <orm:single-field field-name="_id" />
            <orm:concurrency strategy="changed" />
            <orm:field name="_vFCASC" property="VFCASC" behavior="readwrite" uniqueId="b9852ec5-208a-4296-a2c7-d5713ace1c37" type="System.Nullable`1[[System.Boolean, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089]]">
              <orm:column name="VFCASC" sql-type="bit" nullable="true" length="0" scale="0" has-default-value="true" ado-type="Bit" />

    The QuickWatch shows this for the same column during runtime:
    - [5] MetaTable: "'D3_CALBlock'" 40 columns Telerik.OpenAccess.Metadata.Relational.MetaTable
    + base MetaTable: "'D3_CALBlock'" 40 columns Telerik.OpenAccess.Metadata.MetaScopedItem {Telerik.OpenAccess.Metadata.Relational.MetaTable}
    - Columns Count = 40 System.Collections.Generic.IList<Telerik.OpenAccess.Metadata.Relational.MetaColumn> {Telerik.OpenAccess.Metadata.MetadataCollection<Telerik.OpenAccess.Metadata.Relational.MetaColumn>}
    - [0] MetaColumn: "VFCASC" Telerik.OpenAccess.Metadata.Relational.MetaColumn
    + base MetaColumn: "VFCASC" Telerik.OpenAccess.Metadata.MetaItem {Telerik.OpenAccess.Metadata.Relational.MetaColumn}
    AdoType -7 int?
    + BackingUDT null Telerik.OpenAccess.Metadata.Relational.MetaUDT
    Converter "OpenAccessRuntime.Data.OneZero2BooleanConverter" string
    HasDefaultValue false bool
    IsBackendCalculated false bool
    IsBackendVersion false bool
    IsNullable true bool?
    IsPrimaryKey false bool
    Length 0 int?
    Scale 0 int?
    SqlType "bit" string
    + Table MetaTable: "'D3_CALBlock'" 40 columns Telerik.OpenAccess.Metadata.Relational.MetaTable
    + TargetClass null Telerik.OpenAccess.Metadata.MetaPersistentType
    + TargetField null Telerik.OpenAccess.Metadata.MetaPrimitiveMember
    Telerik.OpenAccess.Data.IDataColumn.AssemblyQualifiedName "" string
    Telerik.OpenAccess.Data.IDataColumn.ResolvedLength 0 int?
    Telerik.OpenAccess.Data.IDataColumn.ResolvedScale 0 int?
    Telerik.OpenAccess.Data.IDataColumn.ResolvedSqlType "bit" string
    Telerik.OpenAccess.Data.IDataColumn.UDTName "" string 

    I apologize if the formatting is off.

    Also, I think the generator breaks when the Int32 of the column is substituted with an enumeration and then made nullable.

    Hoping for a speedy response :), John

  9. Doroteya
    Doroteya avatar
    495 posts

    Posted 24 Oct 2014 Link to this post

    Hi John,

    Thank you for the additional information.

    In order to implement the scenario when the value for the property could be provided through an enum, you need to specify the enum as nullable when you change the type of the property. This means that you need to add the "?" sign after the name of the enum. For example:

    If the enum looks like this:
    public enum MyEnum
        Zero = 0,
        One = 1,

    The Type property of VFCASC should be MyEnum?. You can take a look at the attached screenshot.

    I hope this helps. Do let us know if you need further information.

    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
  10. John
    John avatar
    16 posts
    Member since:
    Aug 2014

    Posted 24 Oct 2014 in reply to Doroteya Link to this post

    That would do it.


Back to Top
DevCraft banner