Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

EntityFramework Oracle C# - can't compare Timestamp with Datetime in where clause

S.SchmittNov 2 2017 — edited Nov 2 2017

I am using an Oracle Database and the Nuget Packages

  • Oracle ManagedDataAccess v12.2.1100
  • Oracle.ManagedDataAccess.EntityFramework v12.2.1100
  • EntityFramework v6.0.0

In the Oracle Database there is a field defined with Timestamp(6).

As I am Using Database first, this gets converted into DateTime.

So far so good.

Now I am going to insert the current timestamp into the table:

    DateTime dateTime = DateTime.Now;

    //only 3 parts of milisec

    DateTime zeitStempel = dateTime.AddTicks(-1 * dateTime.Ticks % 10000);

   

using (Entities ctx = new Entities(DBConnect.BuildConnectionString(_bedien, "ModelJobLog")))

{

     JOB job = (from e in ctx.JOB

        where e.PROGNAME == progName

        select e).FirstOrDefault();

     JOBLAEUFE lauf = new JOBLAEUFE();

     lauf.JOBID = job.JOBID;

     lauf.JOB = job;

     lauf.LETZTSTART = zeitStempel;

     ctx.JOBLAEUFE.Add(lauf);

     ctx.SaveChanges();

}

Everything is fine, in my Field i have the value:

"26.10.17 07:39:53,381000000"

Now i store this dateTime in a variable(name zeitStempel) and now i am going for a search for it in this table.

So I still have the same dateTime object and search now for the value in the Database and want to set the current dateTime in another field:

using (Entities ctx = new Entities(DBConnect.BuildConnectionString(_bedien, "ModelJobLog")))

{

try

{

Oracle.ManagedDataAccess.Types.OracleTimeStamp tmstmp = zeitStempel;

JOBLAEUFE lauf = (from e in ctx.JOBLAEUFE

  join j in ctx.JOB on e.JOBID equals j.JOBID

  where j.PROGNAME == progName

  &&( e.LETZTSTART.Equals(zeitStempel)

  || (e.LETZTSTART.Year == zeitStempel.Year

  && e.LETZTSTART.Month == zeitStempel.Month

  && e.LETZTSTART.Day == zeitStempel.Day

  && e.LETZTSTART.Hour == zeitStempel.Hour

  && e.LETZTSTART.Minute == zeitStempel.Minute

  && e.LETZTSTART.Second == zeitStempel.Second

  ))

  select e).FirstOrDefault();

lauf.LETZTEND = DateTime.Now;

ctx.SaveChanges();

}

.

.

.

}

If I compare in the where clause _with_ the Seconds i never get the value of the DB. If i however leave the Seconds out of the where clause, he finds the database record. But of course the minute alone is not precise enough.

Both, e.LETZTSTART and zeitStempel are from DateTime and if I check in debugging all properties are the same.

Kind regards,

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 30 2017
Added on Nov 2 2017
0 comments
1,566 views