当使用默认值执行插入到SYSTIMESTAMP WITH TIME ZONE类型的列时,会引发无效的强制转换异常

时间:2015-01-19 13:12:27

标签: c# oracle odp.net

请你帮助下一个: 我有一个表格,其列类型为SYSTIMESTAMP WITH TIME ZONE,默认值为SYSTIMESTAMP。我首先使用Entity Framework 5数据库。当我尝试在此表中插入实体时,我得到一个例外。异常消息是“商店生成的类型' System.DateTime'无法转换为类型的值System.DateTimeOffset'会员需要{INSERT_DATE'类型' Model.SAMPLE'。“内部异常消息是:“System.DateTime'中的无效转换;到' System.DateTimeOffset'。“ 我使用ODAC 12.1012非托管驱动程序。 我该如何解决这个问题?
样本表脚本:

CREATE TABLE "TEST"."SAMPLE" 
  ( "ID" NUMBER NOT NULL ENABLE, 
    "INSERT_DATE" TIMESTAMP (6) WITH TIME ZONE DEFAULT systimestamp, 
    "TEXT_COLUMN" VARCHAR2(200 BYTE), 
    CONSTRAINT "SAMPLE_PK" PRIMARY KEY ("ID")
 USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 
 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
 TABLESPACE "SYSTEM"  ENABLE
  ) SEGMENT CREATION IMMEDIATE 
 PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
 STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
 TABLESPACE "SYSTEM" ;

edmx文件内容:

 <edmx:Runtime>
    <!-- SSDL content -->
    <edmx:StorageModels>
      <Schema Namespace="Model.Store" Provider="Oracle.DataAccess.Client" ProviderManifestToken="11.2" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
        <EntityType Name="SAMPLE">
          <Key>
            <PropertyRef Name="ID" />
          </Key>
          <Property Name="ID" Type="number" Precision="38" Scale="0" Nullable="false" StoreGeneratedPattern="Identity" />
          <Property Name="INSERT_DATE" Type="timestamp with time zone" Precision="6" StoreGeneratedPattern="Identity" />
          <Property Name="TEXT_COLUMN" Type="varchar2" MaxLength="200" />
        </EntityType>
        <EntityContainer Name="ModelStoreContainer">
          <EntitySet Name="SAMPLE" EntityType="Self.SAMPLE" Schema="TEST" store:Type="Tables" />
        </EntityContainer>
      </Schema>
    </edmx:StorageModels>
    <!-- CSDL content -->
    <edmx:ConceptualModels>
      <Schema Namespace="Model" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
        <EntityContainer Name="vm2" annotation:LazyLoadingEnabled="true">
          <EntitySet Name="SAMPLE" EntityType="Model.SAMPLE" />
        </EntityContainer>
        <EntityType Name="SAMPLE">
          <Key>
            <PropertyRef Name="ID" />
          </Key>
          <Property Name="ID" Type="Decimal" Nullable="false" Precision="38" Scale="0" annotation:StoreGeneratedPattern="Identity" />
          <Property Name="INSERT_DATE" Type="DateTimeOffset" Precision="9" annotation:StoreGeneratedPattern="Identity" />
          <Property Name="TEXT_COLUMN" Type="String" MaxLength="200" FixedLength="false" Unicode="false" />
        </EntityType>
      </Schema>
    </edmx:ConceptualModels>
    <!-- C-S mapping content -->
    <edmx:Mappings>
      <Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
        <EntityContainerMapping StorageEntityContainer="ModelStoreContainer" CdmEntityContainer="vm2">
          <EntitySetMapping Name="SAMPLE">
            <EntityTypeMapping TypeName="Model.SAMPLE">
              <MappingFragment StoreEntitySet="SAMPLE">
                <ScalarProperty Name="TEXT_COLUMN" ColumnName="TEXT_COLUMN" />
                <ScalarProperty Name="INSERT_DATE" ColumnName="INSERT_DATE" />
                <ScalarProperty Name="ID" ColumnName="ID" />
              </MappingFragment>
            </EntityTypeMapping>
          </EntitySetMapping>
        </EntityContainerMapping>
      </Mapping>
    </edmx:Mappings>
  </edmx:Runtime>

提前致谢!

0 个答案:

没有答案