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!

use datetime.today() in where,got wrong sql

3975927Nov 1 2019 — edited Nov 13 2019

I use .NetCore 2.2 ,Oracle.EntityframeWork(v2.19.50)  oracle (11g).

When i use  the condition  "x=>x.C>DateTime.Today()&&x.C<DateTime.Today().AddDays(1)".

I got the sql wrong.

Here is the test:

Model:

public class Parent {

         public string Id { get; set; }

         public string A { get; set; }

         public string B { get; set; }

         public DateTime? C { get; set; }

    }

Linq:

await _dbcontext.Parents.Where(o => o.C >= DateTime.Today && o.C < DateTime.Today.AddDays(1)).Select(o => o.Id).ToListAsync();

General SQL:

SELECT "o"."C", "o"."ID"

    FROM "PARENT" "o"

    WHERE ("o"."C" >= "TRUNC"(SYSDATE))

you can also find the repo in https://github.com/362486122/ef-oracle-test/tree/master

Comments
Post Details
Added on Nov 1 2019
4 comments
390 views