1 Reply Latest reply: Mar 12, 2013 11:10 PM by 995550 RSS

    ODP bug with generated SQL script when using DateTime

    995550
      With EF5, I'm getting some really weird SQL scripts when dealing with DateTime.

      THe follow script works fine.

      var a = db.MOTOR_POOL_RESERVATION
      .Where(o => o.DEPART_DT > new DateTime(2013, 1, 1))
      .Select(o => o.RESERVATION_ID)
      .ToList();

      SELECT "Extent1"."RESERVATION_ID" AS "RESERVATION_ID"
      FROM "MOTORPOOL"."MOTOR_POOL_RESERVATION" "Extent1"
      WHERE ("Extent1"."DEPART_DT" > TO_TIMESTAMP('2013-01-01 00:00:00.000', 'YYYY-MM-DD HH24:MI:SS.FF'))


      But as soon as I create DateTime with year, month or day values forming from a variable, then generated scripts become incorrect.

      var year = 2013;
      var month = 3;


      var dt = new DateTime(year, month, 1);
      var c = db.MOTOR_POOL_RESERVATION
      .Where(o => o.DEPART_DT > dt)
      .Select(o=>o.RESERVATION_ID)
      .ToList();

      see the date is treated a string.

      SELECT "Extent1"."RESERVATION_ID" AS "RESERVATION_ID"
      FROM "MOTORPOOL"."MOTOR_POOL_RESERVATION" "Extent1"
      WHERE ("Extent1"."DEPART_DT" > '2013-03-01 00:00:00')


      var b = db.MOTOR_POOL_RESERVATION
      .Where(o => o.DEPART_DT > new DateTime(year, month, 1))
      .Select(o => o.RESERVATION_ID)
      .ToList();

      same problem with this one.

      SELECT "Extent1"."RESERVATION_ID" AS "RESERVATION_ID"
      FROM "MOTORPOOL"."MOTOR_POOL_RESERVATION" "Extent1"
      WHERE ("Extent1"."DEPART_DT" > '2013-03-01 00:00:00')