Skip to content

Commit 12dc451

Browse files
committed
checking logs
1 parent a1ff208 commit 12dc451

File tree

4 files changed

+28
-43
lines changed

4 files changed

+28
-43
lines changed

src/EFCore.Ydb/src/Storage/Internal/Mapping/YdbDecimalTypeMapping.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.Data.Common;
32
using Microsoft.EntityFrameworkCore.Storage;
43

@@ -36,13 +35,10 @@ protected override void ConfigureParameter(DbParameter parameter)
3635
{
3736
base.ConfigureParameter(parameter);
3837

39-
var p = (byte)(Precision ?? DefaultPrecision);
40-
var s = (byte)(Scale ?? DefaultScale);
38+
if (Precision is { } p)
39+
parameter.Precision = (byte)p;
4140

42-
parameter.Precision = p;
43-
parameter.Scale = s;
44-
45-
if (parameter.Value is decimal d)
46-
parameter.Value = decimal.Round(d, s, MidpointRounding.ToEven);
41+
if (Scale is { } s)
42+
parameter.Scale = (byte)s;
4743
}
4844
}

src/EFCore.Ydb/test/EntityFrameworkCore.Ydb.FunctionalTests/Query/DecimalParameterQueryYdbFixture.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ public class DecimalParameterQueryYdbFixture : SharedStoreFixtureBase<DecimalPar
1010

1111
protected override ITestStoreFactory TestStoreFactory => YdbTestStoreFactory.Instance;
1212

13+
public override async Task InitializeAsync()
14+
{
15+
await base.InitializeAsync();
16+
17+
await using var context = CreateContext();
18+
await context.Database.EnsureCreatedAsync();
19+
}
20+
1321
public class TestContext(DbContextOptions options) : DbContext(options)
1422
{
1523
protected override void OnModelCreating(ModelBuilder modelBuilder)

src/EFCore.Ydb/test/EntityFrameworkCore.Ydb.FunctionalTests/Query/DecimalParameterizedYdbTheoryTest.cs

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -52,52 +52,32 @@ private ParametricDecimalContext NewCtx(int p, int s)
5252
public async Task Decimal_roundtrips_or_rounds_like_ado(int p, int s, decimal value)
5353
{
5454
await using var ctx = NewCtx(p, s);
55+
await ctx.Database.EnsureCreatedAsync();
5556

56-
try
57-
{
58-
var e = new ParamItem { Price = value };
59-
ctx.Add(e);
60-
await ctx.SaveChangesAsync();
57+
var e = new ParamItem { Price = value };
58+
ctx.Add(e);
59+
await ctx.SaveChangesAsync();
6160

62-
var got = await ctx.Items.AsNoTracking().SingleAsync(x => x.Id == e.Id);
61+
var got = await ctx.Items.AsNoTracking().SingleAsync(x => x.Id == e.Id);
6362

64-
var expected = Math.Round(value, s, MidpointRounding.ToEven);
65-
Assert.Equal(expected, got.Price);
63+
var expected = Math.Round(value, s, MidpointRounding.ToEven);
64+
Assert.Equal(expected, got.Price);
6665

67-
var tms = ctx.GetService<IRelationalTypeMappingSource>();
68-
var et = ctx.Model.FindEntityType(typeof(ParamItem))!;
69-
var prop = et.FindProperty(nameof(ParamItem.Price))!;
70-
var mapping = tms.FindMapping(prop)!;
71-
Assert.Equal($"Decimal({p}, {s})", mapping.StoreType);
72-
}
73-
catch (DbUpdateException ex) when ((ex.InnerException?.Message ?? "").Contains("Cannot find table",
74-
StringComparison.OrdinalIgnoreCase))
75-
{
76-
}
77-
catch (Exception ex) when (ex.ToString()
78-
.Contains("EnableParameterizedDecimal", StringComparison.OrdinalIgnoreCase))
79-
{
80-
}
66+
var tms = ctx.GetService<IRelationalTypeMappingSource>();
67+
var et = ctx.Model.FindEntityType(typeof(ParamItem))!;
68+
var prop = et.FindProperty(nameof(ParamItem.Price))!;
69+
var mapping = tms.FindMapping(prop)!;
70+
Assert.Equal($"Decimal({p}, {s})", mapping.StoreType);
8171
}
8272

8373
[Theory]
8474
[MemberData(nameof(OverflowCases))]
8575
public async Task Decimal_overflow_bubbles_up(int p, int s, decimal value)
8676
{
8777
await using var ctx = NewCtx(p, s);
78+
await ctx.Database.EnsureCreatedAsync();
8879

89-
try
90-
{
91-
ctx.Add(new ParamItem { Price = value });
92-
await Assert.ThrowsAsync<DbUpdateException>(() => ctx.SaveChangesAsync());
93-
}
94-
catch (DbUpdateException ex) when ((ex.InnerException?.Message ?? "").Contains("Cannot find table",
95-
StringComparison.OrdinalIgnoreCase))
96-
{
97-
}
98-
catch (Exception ex) when (ex.ToString()
99-
.Contains("EnableParameterizedDecimal", StringComparison.OrdinalIgnoreCase))
100-
{
101-
}
80+
ctx.Add(new ParamItem { Price = value });
81+
await Assert.ThrowsAsync<DbUpdateException>(() => ctx.SaveChangesAsync());
10282
}
10383
}

src/EFCore.Ydb/test/EntityFrameworkCore.Ydb.FunctionalTests/Query/ParametricDecimalContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public ParametricDecimalContext(DbContextOptions<ParametricDecimalContext> optio
1919
protected override void OnModelCreating(ModelBuilder modelBuilder) =>
2020
modelBuilder.Entity<ParamItem>(b =>
2121
{
22+
b.ToTable($"Items_{_p}_{_s}");
2223
b.HasKey(x => x.Id);
2324
b.Property(x => x.Price).HasPrecision(_p, _s);
2425
});

0 commit comments

Comments
 (0)