4 Replies Latest reply on Nov 13, 2019 7:04 AM by 3975927

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

    3975927

      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