Skip to content

Commit 1ca08d7

Browse files
commit
1 parent d3b004d commit 1ca08d7

File tree

4 files changed

+20
-32
lines changed

4 files changed

+20
-32
lines changed

src/EfCore.Ydb/src/Query/Internal/YdbQuerySqlGenerator.cs

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,16 @@
99

1010
namespace EfCore.Ydb.Query.Internal;
1111

12-
public class YdbQuerySqlGenerator : QuerySqlGenerator
12+
public class YdbQuerySqlGenerator(QuerySqlGeneratorDependencies dependencies) : QuerySqlGenerator(dependencies)
1313
{
14-
protected readonly ISqlGenerationHelper SqlGenerationHelper;
15-
protected readonly IRelationalTypeMappingSource TypeMappingSource;
16-
protected bool SkipAliases;
17-
18-
public YdbQuerySqlGenerator(
19-
QuerySqlGeneratorDependencies dependencies,
20-
IRelationalTypeMappingSource typeMappingSource
21-
) : base(dependencies)
22-
{
23-
SqlGenerationHelper = dependencies.SqlGenerationHelper;
24-
TypeMappingSource = typeMappingSource;
25-
}
26-
27-
[return: NotNullIfNotNull("node")]
28-
public override Expression? Visit(Expression? node) => node != null ? base.Visit(node) : null;
14+
private bool SkipAliases { get; set; }
15+
private ISqlGenerationHelper SqlGenerationHelper => Dependencies.SqlGenerationHelper;
2916

3017
protected override Expression VisitColumn(ColumnExpression columnExpression)
3118
{
3219
if (SkipAliases)
3320
{
34-
Sql.Append(SqlGenerationHelper.DelimitIdentifier(columnExpression.Name));
21+
Sql.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(columnExpression.Name));
3522
}
3623
else
3724
{
@@ -139,17 +126,17 @@ private void GenerateUpdateColumnSetters(UpdateExpression updateExpression)
139126
{
140127
foreach (var columnValueSetter in updateExpression.ColumnValueSetters.Skip(1))
141128
{
142-
Sql
143-
.AppendLine(",")
144-
.Append($"{SqlGenerationHelper.DelimitIdentifier(columnValueSetter.Column.Name)} = ");
129+
Sql.AppendLine(",")
130+
.Append(SqlGenerationHelper.DelimitIdentifier(columnValueSetter.Column.Name))
131+
.Append(" = ");
145132
SkipAliases = true;
146133
Visit(columnValueSetter.Value);
147134
SkipAliases = false;
148135
}
149136
}
150137
}
151138

152-
protected void GenerateOnSubquery(
139+
private void GenerateOnSubquery(
153140
IReadOnlyList<ColumnValueSetter>? columnValueSetters,
154141
SelectExpression select
155142
)
@@ -196,9 +183,13 @@ SelectExpression select
196183
}
197184
}
198185

186+
/// <inheritdoc />
199187
protected override void GenerateLimitOffset(SelectExpression selectExpression)
200188
{
201-
if (selectExpression.Limit == null && selectExpression.Offset == null) return;
189+
if (selectExpression.Limit == null && selectExpression.Offset == null)
190+
{
191+
return;
192+
}
202193

203194
Sql.AppendLine().Append("LIMIT ");
204195
if (selectExpression.Limit != null)
@@ -211,14 +202,15 @@ protected override void GenerateLimitOffset(SelectExpression selectExpression)
211202
Sql.Append(ulong.MaxValue.ToString());
212203
}
213204

205+
// ReSharper disable once InvertIf
214206
if (selectExpression.Offset != null)
215207
{
216208
Sql.Append(" OFFSET ");
217209
Visit(selectExpression.Offset);
218210
}
219211
}
220212

221-
private bool IsComplexSelect(SelectExpression select, TableExpressionBase fromTable) =>
213+
private static bool IsComplexSelect(SelectExpression select, TableExpressionBase fromTable) =>
222214
select.Offset != null
223215
|| select.Limit != null
224216
|| select.Having != null

src/EfCore.Ydb/src/Query/Internal/YdbQuerySqlGeneratorFactory.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33

44
namespace EfCore.Ydb.Query.Internal;
55

6-
public class YdbQuerySqlGeneratorFactory(
7-
QuerySqlGeneratorDependencies dependencies,
8-
IRelationalTypeMappingSource typeMappingSource
9-
) : IQuerySqlGeneratorFactory
6+
public class YdbQuerySqlGeneratorFactory(QuerySqlGeneratorDependencies dependencies) : IQuerySqlGeneratorFactory
107
{
11-
public QuerySqlGenerator Create() => new YdbQuerySqlGenerator(dependencies, typeMappingSource);
8+
public QuerySqlGenerator Create() => new YdbQuerySqlGenerator(dependencies);
129
}

src/EfCore.Ydb/test/EfCore.Ydb.FunctionalTests/AllTests/Update/UpdatesYdbTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace EfCore.Ydb.FunctionalTests.AllTests.Update;
1313
// Ignore_before_save_property_is_still_generated,
1414
// SaveChanges_processes_all_tracked_entities.
1515
// They're failing, but I cannot ignore them because they're not virtual
16-
internal class UpdatesYdbTest
16+
public class UpdatesYdbTest
1717
: UpdatesRelationalTestBase<UpdatesYdbTest.UpdatesYdbFixture>
1818
// , UpdatesTestBase<UpdatesYdbTest.UpdatesYdbFixture>
1919
{
@@ -24,8 +24,7 @@ public UpdatesYdbTest(UpdatesYdbFixture fixture) : base(fixture)
2424

2525
public class UpdatesYdbFixture : UpdatesRelationalFixture
2626
{
27-
protected override ITestStoreFactory TestStoreFactory
28-
=> YdbTestStoreFactory.Instance;
27+
protected override ITestStoreFactory TestStoreFactory => YdbTestStoreFactory.Instance;
2928
}
3029

3130
public override void Identifiers_are_generated_correctly()

src/EfCore.Ydb/test/EfCore.Ydb.FunctionalTests/TestUtilities/YdbTestStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private static YdbCommand CreateCommand(
163163
}
164164

165165

166-
private static YdbConnection CreateConnection() => new();
166+
private static YdbConnection CreateConnection() => new(new YdbConnectionStringBuilder());
167167

168168
public override async Task CleanAsync(DbContext context)
169169
{

0 commit comments

Comments
 (0)