Hi! I'm using 3.19.0-beta1 and experience strange error when using custom Execution Strategy. Here is a test to reproduce it:
namespace EfCoreOracleTest
{
[TestFixture]
public class DateTimeOffsetTest
{
public class TestEntity
{
[Key]
[Column("ID")]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; protected set; }
[Column("OPERATION_START_DATE")]
public DateTimeOffset OperationStartDate { get; set; }
}
public class TestDbContext : DbContext
{
public TestDbContext(DbContextOptions options)
: base(options)
{
}
public DbSet<TestEntity> TestEntities { get; set; }
}
public class MyExecutionStrategy : ExecutionStrategy
{
public MyExecutionStrategy(DbContext context, int maxRetryCount, TimeSpan maxRetryDelay)
: base(context, maxRetryCount, maxRetryDelay)
{
}
protected override bool ShouldRetryOn(Exception exception) => false;
}
private Func<TestDbContext> _contextCreator;
[SetUp]
public void SetUp()
{
var options = new DbContextOptionsBuilder<TestDbContext>()
.UseOracle(
"Data Source=....",
pp =>
{
// if comment this line test will succeed
pp.ExecutionStrategy(_ => new MyExecutionStrategy(_.CurrentContext.Context, 1, TimeSpan.Zero));
})
.EnableSensitiveDataLogging(true)
.Options;
_contextCreator = () => new TestDbContext(options);
using var context = _contextCreator();
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
}
[Test]
public async Task TestDateTimeOffset()
{
using (var context = _contextCreator())
{
context.TestEntities.Add(new TestEntity
{
OperationStartDate = DateTimeOffset.Now,
});
context.SaveChanges();
}
using (var context = _contextCreator())
{
var entity = await context.TestEntities.AsQueryable().Where(e => e.Id > 0).FirstOrDefaultAsync();
Assert.NotNull(entity);
Assert.AreEqual(DateTime.Today, entity.OperationStartDate.UtcDateTime.Date);
}
}
}
}
Error says:
Message:
System.InvalidCastException : Unable to cast object of type 'System.DateTime' to type 'System.DateTimeOffset'.
Stack Trace:
DbDataReader.GetFieldValue[T](Int32 ordinal)
If I remove Execution Strategy "pp.ExecutionStrategy(_ => new MyExecutionStrategy(_.CurrentContext.Context, 1, TimeSpan.Zero));", test will pass.