Page 1 of 1

SYSDATE defaults

Posted: Mon 16 Sep 2013 23:13
by travis_thelen
I have a number of columns in my database that have SYSDATE as the default. However, when using the DbContext template those fields are not set in the entities constructor. Why?

Compare that to some flag fields I have with defaults of T or F ...

public COR_PRIVILEGE()
{
this.CORPRIV_PASSIVE_FLAG = @"F";
}

Re: SYSDATE defaults

Posted: Tue 17 Sep 2013 13:08
by MariiaI
travis_thelen wrote:I have a number of columns in my database that have SYSDATE as the default. However, when using the DbContext template those fields are not set in the entities constructor. Why?
The code is generated only for literal default values.

Re: SYSDATE defaults

Posted: Tue 17 Sep 2013 16:55
by travis_thelen
ok so I see there is a custom attribute: devart:DefaultValue="SYSDATE"

How do I test for this in the template? Where is it stored? I would like to customize the template such that if I see SYSDATE then create something like this in the constructor:

this.CORAUM_DATE = DateTime.Now;

I would like to stub in this logic around line 278 in your template.

Thanks,
Travis

Re: SYSDATE defaults

Posted: Wed 18 Sep 2013 14:18
by MariiaI
You can do it in the following way:
1) Add an extended property for the entity properties in the DbContext template. To make the template being used available for editing, copy it to the Model Folder - select 'Copy to Model Folder' from the shortcut menu of the template in the Model Explorer (e.g. DbContext template).

Add the following entry at the 55 line in the DbContext configuration section:

Code: Select all

<#@ extended name="MyDefault" owner="Property" default="" type="System.String" #> 
2) After that the "My Default" property will be added for all your entity properties, and you will be able to set the default value for the necessary property.

3) To make the generated code taking into account this value, you should make an additional change in the template starting from the line 278:
replace this code

Code: Select all

else {
              string formatedDefaultValue = !property.IsEnumType && model.GetModelDescriptor().CanFormatDefaultValue(property.Type, property.DefaultValue) ? codeProvider.FormatPropertyValue(property.Type, property.DefaultValue) : null;
              if (!string.IsNullOrEmpty(formatedDefaultValue)) {
#>
          this.<#= codeProvider.GetValidIdentifier(property.Name) #> = <#= formatedDefaultValue #>;
<#
              }
            }
with this

Code: Select all

else {
              if (!string.IsNullOrEmpty(property.GetProperty("MyDefault").ToString())){
#>
          this.<#= codeProvider.GetValidIdentifier(property.Name) #> = <#= property.GetProperty("MyDefault") #>;
<#
              }
              else {
                string formatedDefaultValue = !property.IsEnumType && model.GetModelDescriptor().CanFormatDefaultValue(property.Type, property.DefaultValue) ? codeProvider.FormatPropertyValue(property.Type, property.DefaultValue) : null;
                if(!string.IsNullOrEmpty(formatedDefaultValue)) {
#>
          this.<#= codeProvider.GetValidIdentifier(property.Name) #> = <#= formatedDefaultValue #>;
<#
                }
              }
            }
Please tell us if this helps.

Re: SYSDATE defaults

Posted: Wed 18 Sep 2013 16:13
by travis_thelen
I am missing something?

You have already set devart:DefaultValue="SYSDATE"! I want to read this value.

I don't want a new MyDefault.

Re: SYSDATE defaults

Posted: Wed 18 Sep 2013 16:39
by travis_thelen
Do I simply substitute "devart:DefaultValue" for "MyDefault" in your example?

Re: SYSDATE defaults

Posted: Thu 19 Sep 2013 12:46
by MariiaI
This default value

Code: Select all

 <Property Name="DATA" Type="DATE" Nullable="false" devart:DefaultValue="SYSDATE" />
is related to the storage part of your model (this is the default value in the database, not in the model ) and it is used for runtime and script generation. It does not affect the code generation for the model.

We have made some changes that will help you to implement your scenario. The changes will be available in the next build of dotConnect for Oracle. We will inform you when it is available for download.

Re: SYSDATE defaults

Posted: Thu 19 Sep 2013 19:20
by travis_thelen
Thanks. I appreaciate it.

Re: SYSDATE defaults

Posted: Tue 24 Sep 2013 07:30
by MariiaI
New build of dotConnect for Oracle 7.9.333 is available for download now!
It can be downloaded from http://www.devart.com/dotconnect/oracle/download.html (trial version) or from Registered Users' Area (for users with valid subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?t=27982.

Re: SYSDATE defaults

Posted: Tue 11 Feb 2014 23:58
by travis_thelen
Can you give me a pointer or code snippet on how to use the new information?

Thanks,
Travis

Re: SYSDATE defaults

Posted: Wed 12 Feb 2014 13:39
by MariiaI
Sorry for the inaccuracy. Changes for SYSDATE defaults, that are available starting from dotConnect for Oracle 7.9.333, were made for other ORMs (LinqConnect, NHibernate), and not completely for Entity Framework models. Starting from the next build of dotConnect for Oracle, which we plan to release this week, this behaviour will be available for Entity Framework models completely, too.
We will post here when new build is available for download.

Re: SYSDATE defaults

Posted: Mon 17 Mar 2014 21:02
by travis_thelen
Is the build available?

Re: SYSDATE defaults

Posted: Wed 19 Mar 2014 11:02
by MariiaI
Please try the latest build of dotConnect for Oracle 8.3.115.
It can be downloaded from http://www.devart.com/dotconnect/oracle/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=1&t=29102.

JIC: it is necessary to set the Default Value to SYSDATE for the corresponding property in the storage part of your model.