DefaultValue for Property

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
PatrikAhlquist
Posts: 21
Joined: Thu 11 Feb 2010 08:40

DefaultValue for Property

Post by PatrikAhlquist » Fri 11 Apr 2014 08:25

Migrating from dotConnect for Oracle v7 and Entity FrameWork 4.0 to dotConnect for Oracle v8.3.135.6 and Entity Framework 6.1. Still using EntityObject template.

Here's an example of an existing table.

Code: Select all

CREATE
	TABLE "PL"."SYSTEMPARAMETRAR"
	(
		"GRUPP"          CHAR(16 BYTE) DEFAULT NULL,
		"LINJE"          CHAR(16 BYTE) DEFAULT NULL,
		"PARAMETER"      CHAR(20 BYTE) DEFAULT NULL NOT NULL ENABLE,
		"PARAMETER_DATA" CHAR(72 BYTE) DEFAULT ' ',
		"TYP"            CHAR(1 BYTE),
		"MAX_STORLEK"    NUMBER(*,0) DEFAULT 0,
		"MIN_STORLEK"    NUMBER(*,0) DEFAULT 0,
		"KOMMENTAR"      CHAR(50 BYTE) DEFAULT ' ',
		"SKP_DATUM" DATE DEFAULT sysdate,
		"SKP_TID" CHAR(8 BYTE) DEFAULT TO_CHAR(sysdate,'HH24:MI:SS'),
		"UPD_DATUM" DATE DEFAULT sysdate,
		"UPD_TID"             CHAR(8 BYTE) DEFAULT TO_CHAR(sysdate,'HH24:MI:SS'),
		"ANTAL_UPPDATERINGAR" NUMBER(*,0) DEFAULT 0,
		CONSTRAINT "SYSTEMPARAMETRAR_PRIM_KEY" PRIMARY KEY ("GRUPP", "LINJE", "PARAMETER") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "PLTSIDX" ENABLE,
		CHECK ( max_storlek         >= 0 ) ENABLE,
		CHECK ( min_storlek         >= 0 ) ENABLE,
		CHECK ( antal_uppdateringar >= 0 ) ENABLE
	)
	PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
	(
		INITIAL 131072 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
	)
	TABLESPACE "PLTS1" ;
Gives me this:

Code: Select all

    /// <summary>
    /// There are no comments for PaperLine.Main.Common.DomainModel.MainModel.SYSTEMPARAMETRAR in the schema.
    /// </summary>
    /// <KeyProperties>
    /// GRUPP
    /// LINJE
    /// PARAMETER
    /// </KeyProperties>
    [EdmEntityTypeAttribute(NamespaceName="PaperLine.Main.Common.DomainModel.MainModel", Name="SYSTEMPARAMETRAR")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class SYSTEMPARAMETRAR : EntityObject    {
        #region Factory Method

        /// <summary>
        /// Create a new SYSTEMPARAMETRAR object.
        /// </summary>
        /// <param name="gRUPP">Initial value of GRUPP.</param>
        /// <param name="lINJE">Initial value of LINJE.</param>
        /// <param name="pARAMETER">Initial value of PARAMETER.</param>
        public static SYSTEMPARAMETRAR CreateSYSTEMPARAMETRAR(string gRUPP, string lINJE, string pARAMETER)
        {
            SYSTEMPARAMETRAR sYSTEMPARAMETRAR = new SYSTEMPARAMETRAR();
            sYSTEMPARAMETRAR.GRUPP = gRUPP;
            sYSTEMPARAMETRAR.LINJE = lINJE;
            sYSTEMPARAMETRAR.PARAMETER = pARAMETER;
            return sYSTEMPARAMETRAR;
        }

        #endregion

        #region Properties
    
        /// <summary>
        /// There are no comments for GRUPP in the schema.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public string GRUPP
        {
            get
            {
                string value = _GRUPP;
                OnGetGRUPP(ref value);
                return value;
            }
            set
            {
                if (_GRUPP != value)
                {
                  OnGRUPPChanging(ref value);
                  ReportPropertyChanging("GRUPP");
                  _GRUPP = StructuralObject.SetValidValue(value, false);
                  ReportPropertyChanged("GRUPP");
                  OnGRUPPChanged();
              }
            }
        }
        private string _GRUPP;
        partial void OnGetGRUPP(ref string value);
        partial void OnGRUPPChanging(ref string value);
        partial void OnGRUPPChanged();
    
        /// <summary>
        /// There are no comments for LINJE in the schema.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public string LINJE
        {
            get
            {
                string value = _LINJE;
                OnGetLINJE(ref value);
                return value;
            }
            set
            {
                if (_LINJE != value)
                {
                  OnLINJEChanging(ref value);
                  ReportPropertyChanging("LINJE");
                  _LINJE = StructuralObject.SetValidValue(value, false);
                  ReportPropertyChanged("LINJE");
                  OnLINJEChanged();
              }
            }
        }
        private string _LINJE;
        partial void OnGetLINJE(ref string value);
        partial void OnLINJEChanging(ref string value);
        partial void OnLINJEChanged();
    
        /// <summary>
        /// There are no comments for PARAMETER in the schema.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public string PARAMETER
        {
            get
            {
                string value = _PARAMETER;
                OnGetPARAMETER(ref value);
                return value;
            }
            set
            {
                if (_PARAMETER != value)
                {
                  OnPARAMETERChanging(ref value);
                  ReportPropertyChanging("PARAMETER");
                  _PARAMETER = StructuralObject.SetValidValue(value, false);
                  ReportPropertyChanged("PARAMETER");
                  OnPARAMETERChanged();
              }
            }
        }
        private string _PARAMETER;
        partial void OnGetPARAMETER(ref string value);
        partial void OnPARAMETERChanging(ref string value);
        partial void OnPARAMETERChanged();
    
        /// <summary>
        /// There are no comments for PARAMETER_DATA in the schema.
        /// </summary>
        [EdmScalarPropertyAttribute()]
        [DataMemberAttribute()]
        public string PARAMETER_DATA
        {
            get
            {
                string value = _PARAMETER_DATA;
                OnGetPARAMETER_DATA(ref value);
                return value;
            }
            set
            {
                if (_PARAMETER_DATA != value)
                {
                  OnPARAMETER_DATAChanging(ref value);
                  ReportPropertyChanging("PARAMETER_DATA");
                  _PARAMETER_DATA = StructuralObject.SetValidValue(value, true);
                  ReportPropertyChanged("PARAMETER_DATA");
                  OnPARAMETER_DATAChanged();
              }
            }
        }
        private string _PARAMETER_DATA = @" ";
        partial void OnGetPARAMETER_DATA(ref string value);
        partial void OnPARAMETER_DATAChanging(ref string value);
        partial void OnPARAMETER_DATAChanged();
    
        /// <summary>
        /// There are no comments for TYP in the schema.
        /// </summary>
        [EdmScalarPropertyAttribute()]
        [DataMemberAttribute()]
        public string TYP
        {
            get
            {
                string value = _TYP;
                OnGetTYP(ref value);
                return value;
            }
            set
            {
                if (_TYP != value)
                {
                  OnTYPChanging(ref value);
                  ReportPropertyChanging("TYP");
                  _TYP = StructuralObject.SetValidValue(value, true);
                  ReportPropertyChanged("TYP");
                  OnTYPChanged();
              }
            }
        }
        private string _TYP;
        partial void OnGetTYP(ref string value);
        partial void OnTYPChanging(ref string value);
        partial void OnTYPChanged();
    
        /// <summary>
        /// There are no comments for MAX_STORLEK in the schema.
        /// </summary>
        [EdmScalarPropertyAttribute()]
        [DataMemberAttribute()]
        public global::System.Nullable<decimal> MAX_STORLEK
        {
            get
            {
                global::System.Nullable<decimal> value = _MAX_STORLEK;
                OnGetMAX_STORLEK(ref value);
                return value;
            }
            set
            {
                if (_MAX_STORLEK != value)
                {
                  OnMAX_STORLEKChanging(ref value);
                  ReportPropertyChanging("MAX_STORLEK");
                  _MAX_STORLEK = StructuralObject.SetValidValue(value);
                  ReportPropertyChanged("MAX_STORLEK");
                  OnMAX_STORLEKChanged();
              }
            }
        }
        private global::System.Nullable<decimal> _MAX_STORLEK = 0m;
        partial void OnGetMAX_STORLEK(ref global::System.Nullable<decimal> value);
        partial void OnMAX_STORLEKChanging(ref global::System.Nullable<decimal> value);
        partial void OnMAX_STORLEKChanged();
    
        /// <summary>
        /// There are no comments for MIN_STORLEK in the schema.
        /// </summary>
        [EdmScalarPropertyAttribute()]
        [DataMemberAttribute()]
        public global::System.Nullable<decimal> MIN_STORLEK
        {
            get
            {
                global::System.Nullable<decimal> value = _MIN_STORLEK;
                OnGetMIN_STORLEK(ref value);
                return value;
            }
            set
            {
                if (_MIN_STORLEK != value)
                {
                  OnMIN_STORLEKChanging(ref value);
                  ReportPropertyChanging("MIN_STORLEK");
                  _MIN_STORLEK = StructuralObject.SetValidValue(value);
                  ReportPropertyChanged("MIN_STORLEK");
                  OnMIN_STORLEKChanged();
              }
            }
        }
        private global::System.Nullable<decimal> _MIN_STORLEK = 0m;
        partial void OnGetMIN_STORLEK(ref global::System.Nullable<decimal> value);
        partial void OnMIN_STORLEKChanging(ref global::System.Nullable<decimal> value);
        partial void OnMIN_STORLEKChanged();
    
        /// <summary>
        /// There are no comments for KOMMENTAR in the schema.
        /// </summary>
        [EdmScalarPropertyAttribute()]
        [DataMemberAttribute()]
        public string KOMMENTAR
        {
            get
            {
                string value = _KOMMENTAR;
                OnGetKOMMENTAR(ref value);
                return value;
            }
            set
            {
                if (_KOMMENTAR != value)
                {
                  OnKOMMENTARChanging(ref value);
                  ReportPropertyChanging("KOMMENTAR");
                  _KOMMENTAR = StructuralObject.SetValidValue(value, true);
                  ReportPropertyChanged("KOMMENTAR");
                  OnKOMMENTARChanged();
              }
            }
        }
        private string _KOMMENTAR = @" ";
        partial void OnGetKOMMENTAR(ref string value);
        partial void OnKOMMENTARChanging(ref string value);
        partial void OnKOMMENTARChanged();
    
        /// <summary>
        /// There are no comments for SKP_DATUM in the schema.
        /// </summary>
        [EdmScalarPropertyAttribute()]
        [DataMemberAttribute()]
        public global::System.Nullable<System.DateTime> SKP_DATUM
        {
            get
            {
                global::System.Nullable<System.DateTime> value = _SKP_DATUM;
                OnGetSKP_DATUM(ref value);
                return value;
            }
            set
            {
                if (_SKP_DATUM != value)
                {
                  OnSKP_DATUMChanging(ref value);
                  ReportPropertyChanging("SKP_DATUM");
                  _SKP_DATUM = StructuralObject.SetValidValue(value);
                  ReportPropertyChanged("SKP_DATUM");
                  OnSKP_DATUMChanged();
              }
            }
        }
        private global::System.Nullable<System.DateTime> _SKP_DATUM = DateTime.Now;
        partial void OnGetSKP_DATUM(ref global::System.Nullable<System.DateTime> value);
        partial void OnSKP_DATUMChanging(ref global::System.Nullable<System.DateTime> value);
        partial void OnSKP_DATUMChanged();
    
        /// <summary>
        /// There are no comments for SKP_TID in the schema.
        /// </summary>
        [EdmScalarPropertyAttribute()]
        [DataMemberAttribute()]
        public string SKP_TID
        {
            get
            {
                string value = _SKP_TID;
                OnGetSKP_TID(ref value);
                return value;
            }
            set
            {
                if (_SKP_TID != value)
                {
                  OnSKP_TIDChanging(ref value);
                  ReportPropertyChanging("SKP_TID");
                  _SKP_TID = StructuralObject.SetValidValue(value, true);
                  ReportPropertyChanged("SKP_TID");
                  OnSKP_TIDChanged();
              }
            }
        }
        private string _SKP_TID = @"to_char(sysdate,'HH24:MI:SS')";
        partial void OnGetSKP_TID(ref string value);
        partial void OnSKP_TIDChanging(ref string value);
        partial void OnSKP_TIDChanged();
    
        /// <summary>
        /// There are no comments for UPD_DATUM in the schema.
        /// </summary>
        [EdmScalarPropertyAttribute()]
        [DataMemberAttribute()]
        public global::System.Nullable<System.DateTime> UPD_DATUM
        {
            get
            {
                global::System.Nullable<System.DateTime> value = _UPD_DATUM;
                OnGetUPD_DATUM(ref value);
                return value;
            }
            set
            {
                if (_UPD_DATUM != value)
                {
                  OnUPD_DATUMChanging(ref value);
                  ReportPropertyChanging("UPD_DATUM");
                  _UPD_DATUM = StructuralObject.SetValidValue(value);
                  ReportPropertyChanged("UPD_DATUM");
                  OnUPD_DATUMChanged();
              }
            }
        }
        private global::System.Nullable<System.DateTime> _UPD_DATUM = DateTime.Now;
        partial void OnGetUPD_DATUM(ref global::System.Nullable<System.DateTime> value);
        partial void OnUPD_DATUMChanging(ref global::System.Nullable<System.DateTime> value);
        partial void OnUPD_DATUMChanged();
    
        /// <summary>
        /// There are no comments for UPD_TID in the schema.
        /// </summary>
        [EdmScalarPropertyAttribute()]
        [DataMemberAttribute()]
        public string UPD_TID
        {
            get
            {
                string value = _UPD_TID;
                OnGetUPD_TID(ref value);
                return value;
            }
            set
            {
                if (_UPD_TID != value)
                {
                  OnUPD_TIDChanging(ref value);
                  ReportPropertyChanging("UPD_TID");
                  _UPD_TID = StructuralObject.SetValidValue(value, true);
                  ReportPropertyChanged("UPD_TID");
                  OnUPD_TIDChanged();
              }
            }
        }
        private string _UPD_TID = @"to_char(sysdate,'HH24:MI:SS')";
        partial void OnGetUPD_TID(ref string value);
        partial void OnUPD_TIDChanging(ref string value);
        partial void OnUPD_TIDChanged();
    
        /// <summary>
        /// There are no comments for ANTAL_UPPDATERINGAR in the schema.
        /// </summary>
        [EdmScalarPropertyAttribute()]
        [DataMemberAttribute()]
        public global::System.Nullable<decimal> ANTAL_UPPDATERINGAR
        {
            get
            {
                global::System.Nullable<decimal> value = _ANTAL_UPPDATERINGAR;
                OnGetANTAL_UPPDATERINGAR(ref value);
                return value;
            }
            set
            {
                if (_ANTAL_UPPDATERINGAR != value)
                {
                  OnANTAL_UPPDATERINGARChanging(ref value);
                  ReportPropertyChanging("ANTAL_UPPDATERINGAR");
                  _ANTAL_UPPDATERINGAR = StructuralObject.SetValidValue(value);
                  ReportPropertyChanged("ANTAL_UPPDATERINGAR");
                  OnANTAL_UPPDATERINGARChanged();
              }
            }
        }
        private global::System.Nullable<decimal> _ANTAL_UPPDATERINGAR = 0m;
        partial void OnGetANTAL_UPPDATERINGAR(ref global::System.Nullable<decimal> value);
        partial void OnANTAL_UPPDATERINGARChanging(ref global::System.Nullable<decimal> value);
        partial void OnANTAL_UPPDATERINGARChanged();

        #endregion
    }
And this:

Code: Select all

        <EntityType Name="SYSTEMPARAMETRAR">
          <Key>
            <PropertyRef Name="GRUPP" />
            <PropertyRef Name="LINJE" />
            <PropertyRef Name="PARAMETER" />
          </Key>
          <Property Name="GRUPP" Type="CHAR" Nullable="false" MaxLength="16" />
          <Property Name="LINJE" Type="CHAR" Nullable="false" MaxLength="16" />
          <Property Name="PARAMETER" Type="CHAR" Nullable="false" MaxLength="20" />
          <Property Name="PARAMETER_DATA" Type="CHAR" MaxLength="72" devart:DefaultValue="' '" DefaultValue=" " />
          <Property Name="TYP" Type="CHAR" MaxLength="1" />
          <Property Name="MAX_STORLEK" Type="decimal" Scale="0" DefaultValue="0" />
          <Property Name="MIN_STORLEK" Type="decimal" Scale="0" DefaultValue="0" />
          <Property Name="KOMMENTAR" Type="CHAR" MaxLength="50" devart:DefaultValue="' '" DefaultValue=" " />
          <Property Name="SKP_DATUM" Type="DATE" devart:DefaultValue="sysdate" />
          <Property Name="SKP_TID" Type="CHAR" MaxLength="8" DefaultValue="to_char(sysdate,'HH24:MI:SS')" />
          <Property Name="UPD_DATUM" Type="DATE" devart:DefaultValue="sysdate" />
          <Property Name="UPD_TID" Type="CHAR" MaxLength="8" DefaultValue="to_char(sysdate,'HH24:MI:SS')" />
          <Property Name="ANTAL_UPPDATERINGAR" Type="decimal" Scale="0" DefaultValue="0" />
        </EntityType>
So when I run the code I get:
Image
And the exception: {"ORA-12899: value too large for column \"PL\".\"SYSTEMPARAMETRAR\".\"SKP_TID\" (actual: 29, maximum: 8)"}

I get the text "to_char(sysdate, 'HH24:MI:SS')" instead of the result from the function.
This worked in EF4.0, have I missed something in my update?

Regards,
Patrik

PatrikAhlquist
Posts: 21
Joined: Thu 11 Feb 2010 08:40

Re: DefaultValue for Property

Post by PatrikAhlquist » Fri 11 Apr 2014 09:53

Ok, so this http://blog.devart.com/set-identity-and ... faultvalue speaks about my problem.

If I manually change to this (directly in the code or in the (devart) entity developer) it works (almost, I can't set the value to anything myself, it always get the to_char-value):

Code: Select all

          <Property Name="SKP_TID" Type="CHAR" MaxLength="8" DefaultValue="to_char(sysdate,'HH24:MI:SS')" StoreGeneratedPattern="Computed" />
          <Property Name="UPD_TID" Type="CHAR" MaxLength="8" DefaultValue="to_char(sysdate,'HH24:MI:SS')" StoreGeneratedPattern="Computed" />
It works for the DATE-columns.

Regards,
Patrik

PatrikAhlquist
Posts: 21
Joined: Thu 11 Feb 2010 08:40

Re: DefaultValue for Property

Post by PatrikAhlquist » Fri 11 Apr 2014 12:22

I tried making the columns NOT NULLABLE but got the same result.

Regards,
Patrik

Shalex
Site Admin
Posts: 8240
Joined: Thu 14 Aug 2008 12:44

Re: DefaultValue for Property

Post by Shalex » Mon 14 Apr 2014 13:43

1. Please remove the DefaultValue and StoreGeneratedPattern attributes from the definitions of your SKP_TID and UPD_TID properties in both CSDL and SSDL parts of the model.

2. Turn on the InsertNullBehaviour.Omit option in your code before using the SYSTEMPARAMETRAR entity:

Code: Select all

    var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
    config.DmlOptions.InsertNullBehaviour = Devart.Data.Oracle.Entity.Configuration.InsertNullBehaviour.Omit;
3. Check the SQL statement generated by Entity Framework:
http://www.devart.com/dotconnect/oracle ... nitor.html
http://www.devart.com/dbmonitor/dbmon3.exe

Does this help?

PatrikAhlquist
Posts: 21
Joined: Thu 11 Feb 2010 08:40

Re: DefaultValue for Property

Post by PatrikAhlquist » Wed 23 Apr 2014 06:42

It does help, but every time I update the model (with the "Update From Database Wizard") all columns on all tables in my model get the 'DefaultValue="to_char(sysdate,'HH24:MI:SS')"' added right back.

Do I really have to do this manually every time?

Regards,
Patrik

Shalex
Site Admin
Posts: 8240
Joined: Thu 14 Aug 2008 12:44

Re: DefaultValue for Property

Post by Shalex » Fri 25 Apr 2014 12:41

The behaviour is changed in the new 8.3.146 build of dotConnect for Oracle: now a property in the generated code is initialized basing on the default value in CSDL only (instead of default values in any of SSDL and CSDL).

Update From Database Wizard compares SSDL part with database. So clear the value in the Default Value attribute in the CSDL part of your model to avoid initialization of the corresponding property in the code. Update From Database Wizard will not see this change and will not offer to update the property in the model.

Also be aware that Update From Database Wizard remembers the choice made once in the wizard. For example: you unchecked the change for a particular column, after this the corresponding change will be unchecked by default in the next runs of Update From Database Wizard.

Does this information help?

PatrikAhlquist
Posts: 21
Joined: Thu 11 Feb 2010 08:40

Re: DefaultValue for Property

Post by PatrikAhlquist » Thu 25 Sep 2014 12:17

I tried something else (see the "default=select max...").

Code: Select all

            <PropertyRef Name="TLOP_NR" />
          </Key>
          <Property Name="TLOP_NR" Type="decimal" Nullable="false" StoreGeneratedPattern="Identity" devart:DefaultValue="(SELECT MAX(TLOP_NR)+1 FROM RH_SUMANALYS)" />
          <Property Name="MASKIN_NR" Type="decimal" Nullable="false" Scale="0" DefaultValue="0" />
          <Property Name="DYGNS_TYP" Type="CHAR" Nullable="false" MaxLength="1" devart:DefaultValue="' '" DefaultValue=" " />
          <Property Name="TIDS_TYP" Type="CHAR" Nullable="false" MaxLength="8" devart:DefaultValue="'ODEF    '" DefaultValue="ODEF    " />
          <Property Name="TIDS_KOD" Type="decimal" Nullable="false" Scale="0" DefaultValue="0" />
          <Property Name="SORT_KVAL" Type="CHAR" Nullable="false" MaxLength="20" devart:DefaultValue="'                    '" DefaultValue="                    " />
          <Property Name="SPEC_ID" Type="decimal" Nullable="false" Scale="0" DefaultValue="0" />
          <Property Name="MALKVALITET" Type="CHAR" MaxLength="6" devart:DefaultValue="'      '" DefaultValue="      " />
          <Property Name="NOMINELL_YTVIKT_MIN" Type="decimal" Nullable="false" Scale="0" DefaultValue="0" />
          <Property Name="NOMINELL_YTVIKT_MAX" Type="decimal" Nullable="false" Scale="0" DefaultValue="0" />
          <Property Name="GRUNDKVALITET" Type="decimal" Nullable="false" Scale="0" DefaultValue="0" />
          <Property Name="ANTAL_UPPDATERINGAR" Type="decimal" Nullable="false" Scale="0" DefaultValue="0" />
          <Property Name="UPD_DATUM" Type="DATE" Nullable="false" devart:DefaultValue="sysdate" />
          <Property Name="UPD_TID" Type="CHAR" Nullable="false" MaxLength="8" />
        </EntityType>
        <EntityType Name="RH_SUMANALYS_RESULTAT">
          <Key>
            <PropertyRef Name="TLOP_NR" />
            <PropertyRef Name="SORT_ID" />
          </Key>
          <Property Name="TLOP_NR" Type="decimal" Nullable="false" />
          <Property Name="SORT_ID" Type="CHAR" Nullable="false" MaxLength="20" />
          <Property Name="PRIM_SORT" Type="CHAR" Nullable="false" MaxLength="20" devart:DefaultValue="'                    '" DefaultValue="                    " />
          <Property Name="SEC_SORT" Type="CHAR" MaxLength="20" devart:DefaultValue="'                    '" DefaultValue="                    " />
          <Property Name="TETR_SORT" Type="CHAR" MaxLength="20" devart:DefaultValue="'                    '" DefaultValue="                    " />
          <Property Name="MAN_EDIT" Type="CHAR" Nullable="false" MaxLength="1" devart:DefaultValue="' '" DefaultValue=" " />
          <Property Name="VIKT" Type="decimal" Nullable="false" DefaultValue="0" />
          <Property Name="ANTAL" Type="decimal" Nullable="false" Scale="0" DefaultValue="0" />
          <Property Name="TID" Type="decimal" Nullable="false" DefaultValue="0" />
          <Property Name="ANTAL_UPPDATERINGAR" Type="decimal" Nullable="false" Scale="0" DefaultValue="0" />
          <Property Name="UPD_DATUM" Type="DATE" Nullable="false" devart:DefaultValue="sysdate" />
          <Property Name="UPD_TID" Type="CHAR" Nullable="false" MaxLength="8" />
        </EntityType>
With the InsertDefaultOrOmit flag.

Code: Select all

            var config = Devart.Data.Oracle.Entity.Configuration.OracleEntityProviderConfig.Instance;
            config.DmlOptions.InsertNullBehaviour = Devart.Data.Oracle.Entity.Configuration.InsertNullBehaviour.InsertDefaultOrOmit;
And it almost worked! I got this back when I added a new RH_SUMANALYS with one child (RH_SUMANALYS_RESULTAT).
The changes to the database were committed successfully, but an error occurred while updating the object context. The ObjectContext might be in an inconsistent state. Inner exception message: The object state cannot be changed. This exception may result from one or more of the primary key properties being set to null. Non-Added objects cannot have null primary key values. See inner exception for details.
dbMonitor shows:

Code: Select all

DECLARE
  updatedRowid ROWID;
BEGIN
INSERT INTO PL.RH_SUMANALYS(TLOP_NR, MASKIN_NR, DYGNS_TYP, TIDS_TYP, TIDS_KOD, SORT_KVAL, SPEC_ID, MALKVALITET, NOMINELL_YTVIKT_MIN, NOMINELL_YTVIKT_MAX, GRUNDKVALITET, ANTAL_UPPDATERINGAR, UPD_DATUM)
VALUES ((SELECT MAX(TLOP_NR)+1 FROM RH_SUMANALYS), :p0, :p1, :p2, :p3, :p4, :p5, '      ', :p6, :p7, :p8, :p9, :p10)
RETURNING ROWID INTO updatedRowid;
OPEN :outParameter FOR SELECT TLOP_NR FROM PL.RH_SUMANALYS WHERE ROWID = updatedRowid;
END;

-- -1 row(s) affected.

and

INSERT INTO PL.RH_SUMANALYS_RESULTAT(TLOP_NR, PRIM_SORT, SEC_SORT, TETR_SORT, MAN_EDIT, VIKT, ANTAL, TID, ANTAL_UPPDATERINGAR, UPD_DATUM)
VALUES (:p0, :p1, :p2, '                    ', :p3, :p4, :p5, :p6, :p7, :p8)

p0 is 100212

But this should be possible, right?

Regards,
Patrik

Shalex
Site Admin
Posts: 8240
Joined: Thu 14 Aug 2008 12:44

Re: DefaultValue for Property

Post by Shalex » Mon 29 Sep 2014 13:38

PatrikAhlquist wrote:

Code: Select all

...
        <EntityType Name="RH_SUMANALYS_RESULTAT">
          <Key>
            <PropertyRef Name="TLOP_NR" />
            <PropertyRef Name="SORT_ID" />
          </Key>
...
... Inner exception message: The object state cannot be changed. This exception may result from one or more of the primary key properties being set to null. ...
dbMonitor shows:

Code: Select all

...
INSERT INTO PL.RH_SUMANALYS_RESULTAT(TLOP_NR, PRIM_SORT, SEC_SORT, TETR_SORT, MAN_EDIT, VIKT, ANTAL, TID, ANTAL_UPPDATERINGAR, UPD_DATUM)
VALUES ...
Have you initialized the SORT_ID property of the RH_SUMANALYS_RESULTAT object in your code?
If this doesn't help, please send us a small test project with the corresponding DDL/DML script so that we can reproduce the issue in our environment.

PatrikAhlquist
Posts: 21
Joined: Thu 11 Feb 2010 08:40

Re: DefaultValue for Property

Post by PatrikAhlquist » Mon 29 Sep 2014 13:39

No, how (and to what value) should I do that?

Shalex
Site Admin
Posts: 8240
Joined: Thu 14 Aug 2008 12:44

Re: DefaultValue for Property

Post by Shalex » Mon 29 Sep 2014 13:49

PatrikAhlquist wrote:how should I do that?
For example: myRH_SUMANALYS_RESULTATObject.SORT_ID = "valid_value";
PatrikAhlquist wrote:to what value
Please set it to any valid value which is allowed by the design of your database.

Post Reply