SYSDATE defaults

SYSDATE defaults

Postby travis_thelen » Mon 16 Sep 2013 23:13

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";
}
travis_thelen
 
Posts: 17
Joined: Thu 14 Mar 2013 15:39

Re: SYSDATE defaults

Postby MariiaI » Tue 17 Sep 2013 13:08

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.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: SYSDATE defaults

Postby travis_thelen » Tue 17 Sep 2013 16:55

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
travis_thelen
 
Posts: 17
Joined: Thu 14 Mar 2013 15:39

Re: SYSDATE defaults

Postby MariiaI » Wed 18 Sep 2013 14:18

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.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: SYSDATE defaults

Postby travis_thelen » Wed 18 Sep 2013 16:13

I am missing something?

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

I don't want a new MyDefault.
travis_thelen
 
Posts: 17
Joined: Thu 14 Mar 2013 15:39

Re: SYSDATE defaults

Postby travis_thelen » Wed 18 Sep 2013 16:39

Do I simply substitute "devart:DefaultValue" for "MyDefault" in your example?
travis_thelen
 
Posts: 17
Joined: Thu 14 Mar 2013 15:39

Re: SYSDATE defaults

Postby MariiaI » Thu 19 Sep 2013 12:46

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.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: SYSDATE defaults

Postby travis_thelen » Thu 19 Sep 2013 19:20

Thanks. I appreaciate it.
travis_thelen
 
Posts: 17
Joined: Thu 14 Mar 2013 15:39

Re: SYSDATE defaults

Postby MariiaI » Tue 24 Sep 2013 07:30

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.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: SYSDATE defaults

Postby travis_thelen » Tue 11 Feb 2014 23:58

Can you give me a pointer or code snippet on how to use the new information?

Thanks,
Travis
travis_thelen
 
Posts: 17
Joined: Thu 14 Mar 2013 15:39

Re: SYSDATE defaults

Postby MariiaI » Wed 12 Feb 2014 13:39

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.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: SYSDATE defaults

Postby travis_thelen » Mon 17 Mar 2014 21:02

Is the build available?
travis_thelen
 
Posts: 17
Joined: Thu 14 Mar 2013 15:39

Re: SYSDATE defaults

Postby MariiaI » Wed 19 Mar 2014 11:02

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.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17


Return to dotConnect for Oracle