Skip to content

Commit 1f5355e

Browse files
committed
checking
1 parent 12dc451 commit 1f5355e

File tree

4 files changed

+43
-52
lines changed

4 files changed

+43
-52
lines changed

src/EFCore.Ydb/src/Storage/Internal/YdbTypeMappingSource.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ RelationalTypeMappingSourceDependencies relationalDependencies
115115

116116
protected override RelationalTypeMapping? FindMapping(in RelationalTypeMappingInfo mappingInfo)
117117
{
118-
if (mappingInfo.ClrType == typeof(decimal)
119-
|| (mappingInfo.StoreTypeName?.StartsWith("Decimal", StringComparison.OrdinalIgnoreCase) ?? false))
118+
if (mappingInfo.ClrType == typeof(decimal))
120119
{
121120
return DecimalCache.GetOrAdd(mappingInfo, static mi => Decimal.Clone(mi));
122121
}

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

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,5 @@ 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-
21-
public class TestContext(DbContextOptions options) : DbContext(options)
22-
{
23-
protected override void OnModelCreating(ModelBuilder modelBuilder)
24-
{
25-
modelBuilder.Entity<ItemDefault>(b =>
26-
{
27-
b.HasKey(x => x.Id);
28-
b.Property(x => x.Price);
29-
});
30-
31-
modelBuilder.Entity<ItemExplicit>(b =>
32-
{
33-
b.HasKey(x => x.Id);
34-
b.Property(x => x.Price).HasPrecision(22, 9);
35-
});
36-
}
37-
}
38-
}
39-
40-
public class ItemDefault
41-
{
42-
public int Id { get; set; }
43-
public decimal Price { get; set; }
44-
}
45-
46-
public class ItemExplicit
47-
{
48-
public int Id { get; set; }
49-
public decimal Price { get; set; }
13+
public class TestContext(DbContextOptions options) : DbContext(options);
5014
}

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

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ private DbContextOptions<ParametricDecimalContext> BuildOptions()
1616

1717
return new DbContextOptionsBuilder<ParametricDecimalContext>()
1818
.UseYdb(cs)
19+
.ReplaceService<IModelCacheKeyFactory, ParametricDecimalContext.CacheKeyFactory>()
1920
.Options;
2021
}
2122

@@ -47,27 +48,37 @@ private DbContextOptions<ParametricDecimalContext> BuildOptions()
4748
private ParametricDecimalContext NewCtx(int p, int s)
4849
=> new(BuildOptions(), p, s);
4950

51+
private static Task DropItemsTableAsync(DbContext ctx, int p, int s) =>
52+
ctx.Database.ExecuteSqlRawAsync($"DROP TABLE IF EXISTS Items_{p}_{s}");
53+
5054
[Theory]
5155
[MemberData(nameof(AdoLikeCases))]
5256
public async Task Decimal_roundtrips_or_rounds_like_ado(int p, int s, decimal value)
5357
{
5458
await using var ctx = NewCtx(p, s);
5559
await ctx.Database.EnsureCreatedAsync();
5660

57-
var e = new ParamItem { Price = value };
58-
ctx.Add(e);
59-
await ctx.SaveChangesAsync();
61+
try
62+
{
63+
var e = new ParamItem { Price = value };
64+
ctx.Add(e);
65+
await ctx.SaveChangesAsync();
6066

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

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

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);
72+
var tms = ctx.GetService<IRelationalTypeMappingSource>();
73+
var et = ctx.Model.FindEntityType(typeof(ParamItem))!;
74+
var prop = et.FindProperty(nameof(ParamItem.Price))!;
75+
var mapping = tms.FindMapping(prop)!;
76+
Assert.Equal($"Decimal({p}, {s})", mapping.StoreType);
77+
}
78+
finally
79+
{
80+
await DropItemsTableAsync(ctx, p, s);
81+
}
7182
}
7283

7384
[Theory]
@@ -77,7 +88,14 @@ public async Task Decimal_overflow_bubbles_up(int p, int s, decimal value)
7788
await using var ctx = NewCtx(p, s);
7889
await ctx.Database.EnsureCreatedAsync();
7990

80-
ctx.Add(new ParamItem { Price = value });
81-
await Assert.ThrowsAsync<DbUpdateException>(() => ctx.SaveChangesAsync());
91+
try
92+
{
93+
ctx.Add(new ParamItem { Price = value });
94+
await Assert.ThrowsAsync<DbUpdateException>(() => ctx.SaveChangesAsync());
95+
}
96+
finally
97+
{
98+
await DropItemsTableAsync(ctx, p, s);
99+
}
82100
}
83101
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.EntityFrameworkCore;
2+
using Microsoft.EntityFrameworkCore.Infrastructure;
23

34
namespace EntityFrameworkCore.Ydb.FunctionalTests.Query;
45

@@ -23,6 +24,15 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) =>
2324
b.HasKey(x => x.Id);
2425
b.Property(x => x.Price).HasPrecision(_p, _s);
2526
});
27+
28+
internal sealed class CacheKeyFactory : IModelCacheKeyFactory
29+
{
30+
public object Create(DbContext context, bool designTime)
31+
{
32+
var ctx = (ParametricDecimalContext)context;
33+
return (context.GetType(), designTime, ctx._p, ctx._s);
34+
}
35+
}
2636
}
2737

2838
public sealed class ParamItem

0 commit comments

Comments
 (0)