It seems to be the insert part that does not work.
public class Test
{
[Fact]
public void ShowBug()
{
var databaseContext = new DatabaseContext();
databaseContext.Database.EnsureDeleted();
databaseContext.Database.EnsureCreated();
var customer = new Customer()
{
Created = SystemClock.Instance.GetCurrentInstant(),
};
databaseContext.Add(customer);
databaseContext.SaveChanges();
databaseContext.Dispose();
//Create a new context to be sure there is no cache involved.
databaseContext = new DatabaseContext();
Customer customerFromDatabase = databaseContext.Customers.First();
Assert.Equal(customer.Created.ToString("yyyy-MM-ddTHH:mm:ss.fffffff", CultureInfo.InvariantCulture), customerFromDatabase.Created.ToString("yyyy-MM-ddTHH:mm:ss.fffffff", CultureInfo.InvariantCulture));
databaseContext.Dispose();
}
}
public class DatabaseContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlServer(@"Data Source=.;Initial Catalog=SampleDatabase;Integrated Security=True;Pooling=False"
, optionsBuilder => optionsBuilder.UseNodaTime()
);
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}
}
public class Customer
{
public int Id { get; set; }
public Instant Created { get; set; }
}
Ps. Could you in the README consider to write something about your thoughts on ZonedDateTime. I know that SQLServer does not have a data type that can hold it. Properly the reason why you did not include it.
If I save a NodaTime Instant in the database then there is only 2 decimals on nanoseconds.
The test below fails with:
It seems to be the insert part that does not work.
Ps. Could you in the README consider to write something about your thoughts on ZonedDateTime. I know that SQLServer does not have a data type that can hold it. Properly the reason why you did not include it.