Skip to content

Commit 066d1db

Browse files
nikitamKirillKurdyukov
authored andcommitted
fix comments
1 parent 4990e45 commit 066d1db

File tree

2 files changed

+21
-32
lines changed

2 files changed

+21
-32
lines changed

src/EFCore.Ydb/src/Query/Internal/YdbSqlExpressionFactory.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,25 @@ public override SqlExpression Coalesce(SqlExpression left, SqlExpression right,
1717
RelationalTypeMapping? typeMapping = null)
1818
{
1919
// For .Sum(x => x.Decimal) EF generates coalesce(sum(x.Decimal), 0.0)) because SUM must have value
20-
var funcExpression = left as SqlFunctionExpression;
21-
var constExpression = right as SqlConstantExpression;
22-
23-
if (funcExpression != null && constExpression != null && constExpression.TypeMapping != null
20+
21+
if (left is SqlFunctionExpression funcExpression
22+
&&
23+
right is SqlConstantExpression constExpression && constExpression.TypeMapping != null
2424
&&
2525
funcExpression.Name.Equals("SUM", StringComparison.OrdinalIgnoreCase)
2626
&&
27+
funcExpression.Arguments != null
28+
&&
2729
constExpression.TypeMapping.DbType == DbType.Decimal
2830
&&
2931
constExpression.Value != null)
3032
{
33+
// get column expression for SUM function expression
34+
var columnExpression = funcExpression.Arguments[0] as ColumnExpression;
35+
3136
var correctRight = new SqlConstantExpression(constExpression.Value,
32-
YdbDecimalTypeMapping.WithMaxPrecision); // in the feature change static max precision/scale to
33-
// to dynamically created correct precision/scale
34-
// it depends on db scheme and can not correctly define only in code
35-
37+
YdbDecimalTypeMapping.GetWithMaxPrecision(columnExpression?.TypeMapping?.Scale));
38+
3639
return base.Coalesce(left, correctRight, typeMapping);
3740
}
3841

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

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,15 @@ public class YdbDecimalTypeMapping : DecimalTypeMapping
1212

1313
public new static YdbDecimalTypeMapping Default => new();
1414

15-
static YdbDecimalTypeMapping()
16-
{
17-
WithMaxPrecision = GetWithMaxPrecision();
18-
}
19-
20-
public static YdbDecimalTypeMapping WithMaxPrecision { get; }
21-
22-
private static YdbDecimalTypeMapping GetWithMaxPrecision()
23-
{
24-
var result = new YdbDecimalTypeMapping(new RelationalTypeMappingParameters(
25-
new CoreTypeMappingParameters(
26-
typeof(decimal)),
27-
storeType: "Decimal",
28-
dbType: System.Data.DbType.Decimal,
29-
precision: MaxPrecision,
30-
scale: DefaultScale)
31-
);
32-
33-
return result;
34-
}
15+
public static YdbDecimalTypeMapping GetWithMaxPrecision(int? scale) =>
16+
new(new RelationalTypeMappingParameters(
17+
new CoreTypeMappingParameters(
18+
typeof(decimal)),
19+
storeType: "Decimal",
20+
dbType: System.Data.DbType.Decimal,
21+
precision: MaxPrecision,
22+
scale: scale ?? DefaultScale)
23+
);
3524

3625
public YdbDecimalTypeMapping() : this(
3726
new RelationalTypeMappingParameters(
@@ -65,8 +54,5 @@ protected override void ConfigureParameter(DbParameter parameter)
6554
parameter.Scale = (byte)s;
6655
}
6756

68-
protected override string GenerateNonNullSqlLiteral(object value)
69-
{
70-
return $"Decimal('{base.GenerateNonNullSqlLiteral(value)}', {this.Precision ?? MaxPrecision}, {this.Scale ?? DefaultScale})";
71-
}
57+
protected override string GenerateNonNullSqlLiteral(object value) => $"Decimal('{base.GenerateNonNullSqlLiteral(value)}', {this.Precision ?? MaxPrecision}, {this.Scale ?? DefaultScale})";
7258
}

0 commit comments

Comments
 (0)