Skip to content

Commit 1030140

Browse files
committed
feat:适配10.0.0
1 parent d88f7c4 commit 1030140

13 files changed

+92
-115
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<VersionPrefix>9.0.2</VersionPrefix>
3+
<VersionPrefix>10.0.0</VersionPrefix>
44
<LangVersion>latest</LangVersion>
55
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
66
<AnalysisLevel>latest</AnalysisLevel>

Directory.Packages.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<Project>
1+
<Project>
22
<PropertyGroup>
3-
<EFCoreVersion>[9.0.0,10.0.0)</EFCoreVersion>
4-
<MicrosoftExtensionsVersion>9.0.0</MicrosoftExtensionsVersion>
3+
<EFCoreVersion>10.0.0</EFCoreVersion>
4+
<MicrosoftExtensionsVersion>10.0.0</MicrosoftExtensionsVersion>
55
<KdbndpVersion>9.0.2</KdbndpVersion>
66
</PropertyGroup>
77

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "9.0.100",
3+
"version": "10.0.101",
44
"rollForward": "latestMajor",
55
"allowPrerelease": false
66
}

src/EFCore.KingbaseES/EFCore.KingbaseES.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<AssemblyName>DotNetCore.EntityFrameworkCore.KingbaseES</AssemblyName>
55
<RootNamespace>DotNetCore.EntityFrameworkCore.KingbaseES</RootNamespace>
66
<PackageId>DotNetCore.EntityFrameworkCore.KingbaseES</PackageId>
7-
<TargetFramework>net9.0</TargetFramework>
8-
<Version>9.0.0</Version>
7+
<TargetFramework>net10.0</TargetFramework>
8+
<Version>10.0.0</Version>
99
<Authors>NCC;Jeffcky</Authors>
1010
<RepositoryType>git</RepositoryType>
1111
<RepositoryUrl>https://github.com/dotnetcore/EntityFrameworkCore.KingbaseES</RepositoryUrl>

src/EFCore.KingbaseES/Query/Internal/KdbndpDeleteConvertingExpressionVisitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Kdbndp.EntityFrameworkCore.KingbaseES.Query.Internal;
44

55
/// <summary>
6-
/// Converts the relational <see cref="NonQueryExpression" /> into a PG-specific <see cref="PgDeleteExpression" />, which
6+
/// Converts the relational <see cref="DeleteExpression" /> into a PG-specific <see cref="PgDeleteExpression" />, which
77
/// precisely models a DELETE statement in KingbaseES. This is done to handle the PG-specific USING syntax for table joining.
88
/// </summary>
99
public class KdbndpDeleteConvertingExpressionVisitor : ExpressionVisitor

src/EFCore.KingbaseES/Query/Internal/KdbndpParameterBasedSqlProcessor.cs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,17 @@ public KdbndpParameterBasedSqlProcessor(
2727
/// any release. You should only use it directly in your code with extreme caution and knowing that
2828
/// doing so can result in application failures when updating to a new Entity Framework Core release.
2929
/// </summary>
30-
public override Expression Optimize(
31-
Expression queryExpression,
32-
IReadOnlyDictionary<string, object?> parametersValues,
33-
out bool canCache)
30+
public override Expression Process(Expression queryExpression, ParametersCacheDecorator parametersDecorator)
3431
{
35-
queryExpression = base.Optimize(queryExpression, parametersValues, out canCache);
32+
queryExpression = base.Process(queryExpression, parametersDecorator);
3633

3734
queryExpression = new KdbndpDeleteConvertingExpressionVisitor().Process(queryExpression);
3835

3936
return queryExpression;
4037
}
4138

42-
/// <inheritdoc />
43-
protected override Expression ProcessSqlNullability(
44-
Expression selectExpression,
45-
IReadOnlyDictionary<string, object?> parametersValues,
46-
out bool canCache)
47-
{
48-
Check.NotNull(selectExpression, nameof(selectExpression));
49-
Check.NotNull(parametersValues, nameof(parametersValues));
5039

51-
return new KdbndpSqlNullabilityProcessor(Dependencies, Parameters).Process(
52-
selectExpression, parametersValues, out canCache);
53-
}
40+
/// <inheritdoc />
41+
protected override Expression ProcessSqlNullability(Expression selectExpression, ParametersCacheDecorator parametersDecorator)
42+
=> new KdbndpSqlNullabilityProcessor(Dependencies, Parameters).Process(selectExpression, parametersDecorator);
5443
}

src/EFCore.KingbaseES/Query/Internal/KdbndpQueryCompilationContext.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ public KdbndpQueryCompilationContext(
1919
RelationalQueryCompilationContextDependencies relationalDependencies,
2020
bool async)
2121
: this(
22-
dependencies, relationalDependencies, async, precompiling: false,
23-
nonNullableReferenceTypeParameters: null)
22+
dependencies, relationalDependencies, async, precompiling: false)
2423
{
2524
}
2625

@@ -34,9 +33,8 @@ public KdbndpQueryCompilationContext(
3433
QueryCompilationContextDependencies dependencies,
3534
RelationalQueryCompilationContextDependencies relationalDependencies,
3635
bool async,
37-
bool precompiling,
38-
IReadOnlySet<string>? nonNullableReferenceTypeParameters)
39-
: base(dependencies, relationalDependencies, async, precompiling, nonNullableReferenceTypeParameters)
36+
bool precompiling)
37+
: base(dependencies, relationalDependencies, async, precompiling)
4038
{
4139
}
4240

src/EFCore.KingbaseES/Query/Internal/KdbndpQueryCompilationContextFactory.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,5 @@ public virtual QueryCompilationContext Create(bool async)
4545
/// </summary>
4646
public virtual QueryCompilationContext CreatePrecompiled(bool async, IReadOnlySet<string> nonNullableReferenceTypeParameters)
4747
=> new KdbndpQueryCompilationContext(
48-
_dependencies, _relationalDependencies, async, precompiling: true,
49-
nonNullableReferenceTypeParameters);
48+
_dependencies, _relationalDependencies, async, precompiling: true);
5049
}

src/EFCore.KingbaseES/Query/Internal/KdbndpQueryableMethodTranslatingExpressionVisitor.cs

Lines changed: 45 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -206,30 +206,50 @@ protected override ShapedQueryExpression TransformJsonQueryToTable(JsonQueryExpr
206206
var columnInfos = new List<PgTableValuedFunctionExpression.ColumnInfo>();
207207

208208
// We're only interested in properties which actually exist in the JSON, filter out uninteresting shadow keys
209-
foreach (var property in GetAllPropertiesInHierarchy(jsonQueryExpression.EntityType))
209+
foreach (var property in jsonQueryExpression.StructuralType.GetPropertiesInHierarchy())
210210
{
211211
if (property.GetJsonPropertyName() is string jsonPropertyName)
212212
{
213213
columnInfos.Add(
214214
new PgTableValuedFunctionExpression.ColumnInfo
215215
{
216-
Name = jsonPropertyName, TypeMapping = property.GetRelationalTypeMapping()
216+
Name = jsonPropertyName,
217+
TypeMapping = property.GetRelationalTypeMapping()
217218
});
218219
}
219220
}
220221

221-
// Navigations represent nested JSON owned entities, which we also add to the AS clause, but with the JSON type.
222-
foreach (var navigation in GetAllNavigationsInHierarchy(jsonQueryExpression.EntityType)
223-
.Where(
224-
n => n.ForeignKey.IsOwnership
225-
&& n.TargetEntityType.IsMappedToJson()
226-
&& n.ForeignKey.PrincipalToDependent == n))
222+
switch (jsonQueryExpression.StructuralType)
227223
{
228-
var jsonNavigationName = navigation.TargetEntityType.GetJsonPropertyName();
229-
Check.DebugAssert(jsonNavigationName is not null, $"No JSON property name for navigation {navigation.Name}");
224+
case IEntityType entityType:
225+
foreach (var navigation in entityType.GetNavigationsInHierarchy()
226+
.Where(n => n.ForeignKey.IsOwnership
227+
&& n.TargetEntityType.IsMappedToJson()
228+
&& n.ForeignKey.PrincipalToDependent == n))
229+
{
230+
var jsonNavigationName = navigation.TargetEntityType.GetJsonPropertyName();
231+
Check.DebugAssert(jsonNavigationName is not null, $"No JSON property name for navigation {navigation.Name}");
232+
233+
columnInfos.Add(
234+
new PgTableValuedFunctionExpression.ColumnInfo { Name = jsonNavigationName, TypeMapping = jsonTypeMapping });
235+
}
236+
237+
break;
238+
239+
case IComplexType complexType:
240+
foreach (var complexProperty in complexType.GetComplexProperties())
241+
{
242+
var jsonPropertyName = complexProperty.ComplexType.GetJsonPropertyName();
243+
Check.DebugAssert(jsonPropertyName is not null, $"No JSON property name for complex property {complexProperty.Name}");
244+
245+
columnInfos.Add(
246+
new PgTableValuedFunctionExpression.ColumnInfo { Name = jsonPropertyName, TypeMapping = jsonTypeMapping });
247+
}
230248

231-
columnInfos.Add(
232-
new PgTableValuedFunctionExpression.ColumnInfo { Name = jsonNavigationName, TypeMapping = jsonTypeMapping });
249+
break;
250+
251+
default:
252+
throw new UnreachableException();
233253
}
234254

235255
// json_to_recordset requires the nested JSON document - it does not accept a path within a containing JSON document (like SQL
@@ -254,21 +274,12 @@ protected override ShapedQueryExpression TransformJsonQueryToTable(JsonQueryExpr
254274
return new ShapedQueryExpression(
255275
selectExpression,
256276
new RelationalStructuralTypeShaperExpression(
257-
jsonQueryExpression.EntityType,
277+
jsonQueryExpression.StructuralType,
258278
new ProjectionBindingExpression(
259279
selectExpression,
260280
new ProjectionMember(),
261281
typeof(ValueBuffer)),
262282
false));
263-
264-
// TODO: Move these to IEntityType?
265-
static IEnumerable<IProperty> GetAllPropertiesInHierarchy(IEntityType entityType)
266-
=> entityType.GetAllBaseTypes().Concat(entityType.GetDerivedTypesInclusive())
267-
.SelectMany(t => t.GetDeclaredProperties());
268-
269-
static IEnumerable<INavigation> GetAllNavigationsInHierarchy(IEntityType entityType)
270-
=> entityType.GetAllBaseTypes().Concat(entityType.GetDerivedTypesInclusive())
271-
.SelectMany(t => t.GetDeclaredNavigations());
272283
}
273284

274285
/// <summary>
@@ -1096,46 +1107,18 @@ protected override bool IsValidSelectExpressionForExecuteUpdate(
10961107
/// any release. You should only use it directly in your code with extreme caution and knowing that
10971108
/// doing so can result in application failures when updating to a new Entity Framework Core release.
10981109
/// </summary>
1099-
protected override bool IsValidSelectExpressionForExecuteDelete(
1100-
SelectExpression selectExpression,
1101-
StructuralTypeShaperExpression shaper,
1102-
[NotNullWhen(true)] out TableExpression? tableExpression)
1103-
{
1104-
// The default relational behavior is to allow only single-table expressions, and the only permitted feature is a predicate.
1105-
// Here we extend this to also inner joins to tables, which we generate via the KingbaseES-specific USING construct.
1106-
if (selectExpression is
1107-
{
1108-
Orderings: [],
1109-
Offset: null,
1110-
Limit: null,
1111-
GroupBy: [],
1112-
Having: null
1113-
})
1114-
{
1115-
TableExpressionBase? table = null;
1116-
if (selectExpression.Tables.Count == 1)
1117-
{
1118-
table = selectExpression.Tables[0];
1119-
}
1120-
else if (selectExpression.Tables.All(t => t is TableExpression or InnerJoinExpression))
1121-
{
1122-
var projectionBindingExpression = (ProjectionBindingExpression)shaper.ValueBufferExpression;
1123-
var entityProjectionExpression =
1124-
(StructuralTypeProjectionExpression)selectExpression.GetProjection(projectionBindingExpression);
1125-
var column = entityProjectionExpression.BindProperty(shaper.StructuralType.GetProperties().First());
1126-
table = selectExpression.Tables.Select(t => t.UnwrapJoin()).Single(t => t.Alias == column.TableAlias);
1127-
}
1128-
1129-
if (table is TableExpression te)
1130-
{
1131-
tableExpression = te;
1132-
return true;
1133-
}
1134-
}
1135-
1136-
tableExpression = null;
1137-
return false;
1138-
}
1110+
protected override bool IsValidSelectExpressionForExecuteDelete(SelectExpression selectExpression)
1111+
// The default relational behavior is to allow only single-table expressions, and the only permitted feature is a predicate.
1112+
// Here we extend this to also inner joins to tables, which we generate via the PostgreSQL-specific USING construct.
1113+
=> selectExpression is
1114+
{
1115+
Orderings: [],
1116+
Offset: null,
1117+
Limit: null,
1118+
GroupBy: [],
1119+
Having: null
1120+
}
1121+
&& selectExpression.Tables[0] is TableExpression && selectExpression.Tables.Skip(1).All(t => t is InnerJoinExpression);
11391122

11401123
// KingbaseES unnest is guaranteed to return output rows in the same order as its input array,
11411124
// https://www.KingbaseES.org/docs/current/functions-array.html.

src/EFCore.KingbaseES/Query/Internal/KdbndpSqlNullabilityProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,5 +737,5 @@ private static bool MayContainNulls(SqlExpression arrayExpression)
737737
// Note that we can check parameter values for null since we cache by the parameter nullability; but we cannot do the same for bool.
738738
private bool IsNull(SqlExpression? expression)
739739
=> expression is SqlConstantExpression { Value: null }
740-
|| expression is SqlParameterExpression { Name: string parameterName } && ParameterValues[parameterName] is null;
740+
|| expression is SqlParameterExpression { Name: string parameterName } && ParametersDecorator.IsNull(parameterName);
741741
}

0 commit comments

Comments
 (0)