none
Entity Framework exception Year, Month, and Day parameters describe an un-representable DateTime RRS feed

  • General discussion

  • Hi,

    I have problem with connecting Entity Framework with Oracle.

    I wrote a select to take DATETIME value (Gregorian), but in Oracle I have (julian) date, so I've got exception System.ArgumentOutOfRangeException 'Year, Month, and Day parameters describe an un-representable DateTime'.

    I've got table on ORACLE DB:

    create table TEST_TABLE (
    
    ID NUMBER(5) NOT NULL,
    
    DATE_ADD DATE NOT NULL,
    
    DESCRIPTION VARCHAR2(10),
     
    CONSTRAINT TEST_TABLE_PK PRIMARY KEY(ID)
    
    );
    
    Insert into TEST_TABLE (ID, DATE_ADD, DESCRIPTION) VALUES (1,TO_DATE('1','J'), 'DESC1');
    

    My generated class looks:

    public partial class TEST_TABLE
    
      {
      public short ID { get; set; }
    
      public System.DateTime DATE_ADD { get; set; }
    
      public string DESCRIPTION { get; set; }
    
      }
    

     

    I wrote query:

    using(Entities en52 = new Entities())
    
    {
      var temp = from e in en52.TEST_TABLE
      select e.DATE_ADD;
    
      foreach(var item in temp)
      {
          MessageBox.Show(item.ToString());
      }
    }
    

     

    When I have date -4712 from Oracle, then I will have an exception.

     

    SSDL content

    <EntityType Name="TEST_TABLE">
      <Key>
      <PropertyRef Name="ID" />
      </Key>
      <Property Name="ID" Type="number" Precision="5" Scale="0" Nullable="false" />
      <Property Name="DATE_ADD" Type="date" Nullable="false" />
      <Property Name="DESCRIPTION" Type="varchar2" MaxLength="10" />
    </EntityType>
    

     

    CSDL content

    <EntityType Name="TEST_TABLE">
      <Key>
      <PropertyRef Name="ID" />
      </Key>
      <Property Name="ID" Type="Int16" Nullable="false" />
      <Property Name="DATE_ADD" Type="DateTime" Nullable="false" />
      <Property Name="DESCRIPTION" Type="String" MaxLength="10" FixedLength="false" Unicode="false" />
    </EntityType>
    

     

    C-S mapping content

    <EntitySetMapping Name="TEST_TABLE">
      <EntityTypeMapping TypeName="Model.TEST_TABLE">
      <MappingFragment StoreEntitySet="TEST_TABLE">
      <ScalarProperty Name="DESCRIPTION" ColumnName="DESCRIPTION" />
      <ScalarProperty Name="DATE_ADD" ColumnName="DATE_ADD" />
      <ScalarProperty Name="ID" ColumnName="ID" />
      </MappingFragment>
      </EntityTypeMapping>
    </EntitySetMapping>
    

     

     

    Can anybody help me resolve this problem?

    Thanks!

    • Moved by CoolDadTx Friday, April 25, 2014 3:15 PM EF related
    Friday, April 25, 2014 10:45 AM

All replies

  • Hello,

    For this error, it usually shows you are under below scenario:

    DataTime date=new DataTime(month,day, year);

    However, The DateTime constructor you are calling accepts parameters in the order year, month, day so it should be:

    DataTime date=new DataTime(year,month,day);

    In your query, you are providing them in the order month, day, year(Maybe).

    And for it, i made a test with SQLServer, it could work fine with the same schema. I would like suggest you psoting it to https://community.oracle.com/community/developer/english since the EF Provider for Oracle is provided by Oracle.

    Regards


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 28, 2014 3:31 AM
    Moderator
  • Thanks for answer,

    this problem occurs when I have a year -4712.

    The Microsoft DateTime accept the year (1 through 9999).

    I must validate year but I don't know on which level, maybe I must change *.tt files.

    Monday, April 28, 2014 8:00 AM