Entity Framework Oracle Timestamp

纵饮孤独 提交于 2020-06-24 16:46:51

问题


We have T_SC_SERVICE table with a INSTANCE_ID column which is type Timestamp(6) in Oracle.

I'm using .NET Framework 4.5, Entity Framework 6 and DB first approaches.

I'm trying to Add and Select item from this table with using LINQ.

Insert with LINQ as shown below:

Service newItem = new Service()  
{  
    InstanceId = DateTime.Now,  
};  


this.ObjectSet.Add(newItem);  
this.SaveChanges(); 

That LINQ generates SQL as below. As you can see INSTANCE_ID parameter is send as a DateTime as expected.

insert into "DGARSMART"."T_SC_SERVICE"("INSTANCE_ID")  
values (:p0)  

-- :p0: '29.08.2019 07:33:38' (Type = DateTime)  

-- Executing at 29.08.2019 07:33:38 +03:00  

-- Completed in 66 ms with result: 1  

Here is my Problem:

Select with LINQ as shown below:

internal Service GetServiceByInstanceId(DateTime instanceId)
{
     return this.ObjectSet.FirstOrDefault(i => i.InstanceId == instanceId);
}

That LINQ generates SQL as below. As you can see Instance_ID is send as a Date not DateTime. So it always return Null. This is the same entity object and same model. I could not figure out why this LINQ is sending DateTime as type of Date instead of DateTime.

SELECT   
"Extent1"."INSTANCE_ID" AS "INSTANCE_ID",   
FROM "DGARSMART"."T_SC_SERVICE" "Extent1"  
WHERE (("Extent1"."INSTANCE_ID" = :p__linq__0) AND (:p__linq__0 IS NOT NULL)) AND (ROWNUM <= (1)   

-- p__linq__0: '29.08.2019 07:33:38' (Type = Date)  

-- Executing at 29.08.2019 07:34:47 +03:00  

-- Completed in 5 ms with result: OracleDataReader  

I'm using these packages:

 <package id="Oracle.ManagedDataAccess" version="12.2.1100" targetFramework="net45" />

 <package id="Oracle.ManagedDataAccess.EntityFramework" version="12.2.20190115" targetFramework="net45" />

 <package id="EntityFramework" version="6.0.0" targetFramework="net45" />

回答1:


I reached to Oracle team and they accepted that it is a bug (Bug id : 30294734). You can check my issue on : https://community.oracle.com/thread/4288922, we need to wait for the new version of Oracle.ManagedDataAccess.EntityFramework it will be fixed.

However, as a workaround we used SQLRawQuery, it worked for us.

  var service = dbContext.Database.SqlQuery("SELECT * FROM T_SC_SERVICE WHERE INSTANCE_ID > :instanceId", new OracleParameter("instanceId", OracleDbType.TimeStamp, LastTimestamp, System.Data.ParameterDirection.Input)).FirstOrDefault(); 


来源:https://stackoverflow.com/questions/57765675/entity-framework-oracle-timestamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!