1

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" />
Selim Yildiz
  • 5,254
  • 6
  • 18
  • 28

1 Answers1

0

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(); 

EDIT:

"This bug was fixed with ODP.NET 19.6 and higher." as stated in the oracle bug thread.

Selim Yildiz
  • 5,254
  • 6
  • 18
  • 28