-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed as not planned
Description
I have a class with a decimal property. I wanted to order all instances of the class by the decimal property within the SQLite database.
I created three instances with these decimal values { 7m, 84.3m, 13.4m }. After running an OrderBy function, I expected it to order it to { 7m, 13.4m, 84.3m } but instead it ordered it to { 13.4m, 7m, 84.3m }
Steps to reproduce
Please run the test below
public class TestEntity : Entity
{
public TestEntity(decimal @decimal) => Decimal = @decimal;
protected TestEntity()
{
}
public decimal Decimal { get; set; }
}
[TestFixture]
public class DecimalSortingTests : DbTests
{
[Test]
public async Task GivenClassWithDecimalColumn_WhenIOrderBy_ItOrdersCorrectly()
{
decimal[] decimals = { 7m, 84.3m, 13.4m };
IEnumerable<TestEntity> testClasses = decimals.Select(@decimal => new TestEntity(@decimal));
using (DbContext dbContext = GetDbContext())
{
dbContext.Set<TestEntity>().AddRange(testClasses);
await dbContext.SaveChangesAsync();
}
List<TestEntity> entities;
using (DbContext dbContext = GetDbContext())
{
entities = await dbContext.Set<TestEntity>()
.OrderBy(x => x.Decimal)
.ToListAsync();
}
List<TestEntity> list = entities.ToList();
Assert.That(list.Count, Is.EqualTo(decimals.Length));
Assert.That(list.ToArray()[0].Decimal, Is.EqualTo(7m));
Assert.That(list.ToArray()[1].Decimal, Is.EqualTo(13.4m));
Assert.That(list.ToArray()[2].Decimal, Is.EqualTo(84.3m));
}
private class TestDbContext : DbContext
{
public TestDbContext(DbContextOptions options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TestEntity>();
base.OnModelCreating(modelBuilder);
}
}
private DbContext GetDbContext()
{
DbContextOptions<TestDbContext> options = new DbContextOptionsBuilder<TestDbContext>()
.UseSqlite(SqliteConnection)
.EnableSensitiveDataLogging()
.Options;
TestDbContext dbContext = new TestDbContext(options);
dbContext.Database.EnsureCreated();
return dbContext;
}
} Expected: 7m
But was: 13.4m
Further technical details
EF Core version: 2.0.0
Database Provider: Microsoft.EntityFrameworkCore.Sqlite
Operating system: Windows 10 64x
IDE: Visual Studio 2017
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels