SYSDATE defaults
-
- Posts: 20
- Joined: Thu 14 Mar 2013 15:39
SYSDATE defaults
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";
}
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
The code is generated only for literal default values.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?
-
- Posts: 20
- Joined: Thu 14 Mar 2013 15:39
Re: SYSDATE defaults
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
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
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:
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
with this
Please tell us if this helps.
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" #>
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 #>;
<#
}
}
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 #>;
<#
}
}
}
-
- Posts: 20
- Joined: Thu 14 Mar 2013 15:39
Re: SYSDATE defaults
I am missing something?
You have already set devart:DefaultValue="SYSDATE"! I want to read this value.
I don't want a new MyDefault.
You have already set devart:DefaultValue="SYSDATE"! I want to read this value.
I don't want a new MyDefault.
-
- Posts: 20
- Joined: Thu 14 Mar 2013 15:39
Re: SYSDATE defaults
Do I simply substitute "devart:DefaultValue" for "MyDefault" in your example?
Re: SYSDATE defaults
This default value
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.
Code: Select all
<Property Name="DATA" Type="DATE" Nullable="false" devart:DefaultValue="SYSDATE" />
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.
-
- Posts: 20
- Joined: Thu 14 Mar 2013 15:39
Re: SYSDATE defaults
Thanks. I appreaciate it.
Re: SYSDATE defaults
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.
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.
-
- Posts: 20
- Joined: Thu 14 Mar 2013 15:39
Re: SYSDATE defaults
Can you give me a pointer or code snippet on how to use the new information?
Thanks,
Travis
Thanks,
Travis
Re: SYSDATE defaults
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.
We will post here when new build is available for download.
-
- Posts: 20
- Joined: Thu 14 Mar 2013 15:39
Re: SYSDATE defaults
Is the build available?
Re: SYSDATE defaults
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.
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.