Skip to content

Commit 876a259

Browse files
fix
1 parent 8bdb778 commit 876a259

File tree

3 files changed

+2
-43
lines changed

3 files changed

+2
-43
lines changed
Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Data;
31
using System.Diagnostics.CodeAnalysis;
4-
using EntityFrameworkCore.Ydb.Storage.Internal.Mapping;
52
using Microsoft.EntityFrameworkCore.Query;
63
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
74
using Microsoft.EntityFrameworkCore.Storage;
@@ -13,32 +10,4 @@ public class YdbSqlExpressionFactory(SqlExpressionFactoryDependencies dependenci
1310
[return: NotNullIfNotNull("sqlExpression")]
1411
public override SqlExpression? ApplyTypeMapping(SqlExpression? sqlExpression, RelationalTypeMapping? typeMapping) =>
1512
base.ApplyTypeMapping(sqlExpression, typeMapping);
16-
17-
public override SqlExpression Coalesce(SqlExpression left, SqlExpression right,
18-
RelationalTypeMapping? typeMapping = null)
19-
{
20-
// For .Sum(x => x.Decimal) EF generates coalesce(sum(x.Decimal), 0.0)) because SUM must have value
21-
if (left is SqlFunctionExpression funcExpression
22-
&&
23-
right is SqlConstantExpression { TypeMapping: not null } constExpression
24-
&&
25-
funcExpression.Name.Equals("SUM", StringComparison.OrdinalIgnoreCase)
26-
&&
27-
funcExpression.Arguments != null
28-
&&
29-
constExpression.TypeMapping.DbType == DbType.Decimal
30-
&&
31-
constExpression.Value != null)
32-
{
33-
// get column expression for SUM function expression
34-
var columnExpression = funcExpression.Arguments[0] as ColumnExpression;
35-
36-
var correctRight = new SqlConstantExpression(constExpression.Value,
37-
YdbDecimalTypeMapping.CreateMaxPrecision(columnExpression?.TypeMapping?.Scale));
38-
39-
return base.Coalesce(left, correctRight, typeMapping);
40-
}
41-
42-
return base.Coalesce(left, right, typeMapping);
43-
}
4413
}

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,9 @@ public class YdbDecimalTypeMapping : DecimalTypeMapping
77
{
88
private const byte DefaultPrecision = 22;
99
private const byte DefaultScale = 9;
10-
private const byte MaxPrecision = 35;
1110

1211
public new static YdbDecimalTypeMapping Default => new();
1312

14-
public static YdbDecimalTypeMapping CreateMaxPrecision(int? scale) => new(
15-
new RelationalTypeMappingParameters(
16-
new CoreTypeMappingParameters(typeof(decimal)),
17-
storeType: "Decimal",
18-
dbType: System.Data.DbType.Decimal,
19-
precision: MaxPrecision,
20-
scale: scale ?? DefaultScale
21-
)
22-
);
23-
2413
private YdbDecimalTypeMapping() : this(
2514
new RelationalTypeMappingParameters(
2615
new CoreTypeMappingParameters(typeof(decimal)),

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ private static DbContextOptions<ParametricDecimalContext> BuildOptions() =>
1212
new DbContextOptionsBuilder<ParametricDecimalContext>()
1313
.UseYdb("Host=localhost;Port=2136")
1414
.EnableServiceProviderCaching(false)
15+
.LogTo(Console.WriteLine)
1516
.Options;
1617

1718
public static TheoryData<int, int, decimal> SuccessCases => new()
@@ -99,7 +100,7 @@ public async Task Should_SumDecimal_When_ValueFitsPrecisionAndScale(int p, int s
99100
for (var i = 0; i < multiplier; i++)
100101
ctx.Add(new ParamItem { Price = value });
101102
await ctx.SaveChangesAsync();
102-
var got = await ctx.Items.SumAsync(x => x.Price);
103+
var got = await ctx.Items.Select(x => x.Price).SumAsync();
103104

104105
Assert.Equal(value * multiplier, got);
105106

0 commit comments

Comments
 (0)