use datetime.today() in where,got wrong sql — oracle-tech

    Forum Stats

  • 3,715,652 Users
  • 2,242,819 Discussions
  • 7,845,478 Comments

Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

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

3975927
3975927 Member Posts: 11
edited November 2019 in ODP.NET

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 string Id { get; set; }         public string A { get; set; }         public string B { get; set; }         public DateTime? C { get; set; }    }public class Parent {

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

Answers

Sign In or Register to comment.