Skip to content

Commit 5f85f93

Browse files
authored
Fixes and optimizations in ToString() calls (#1780)
* Use char overload of string.Join, fix SparseFieldSetExpression * Add ToFullString() method on QueryLayer and ResourceFieldAttribute * Optimize StringBuilder calls to avoid calling ToString() twice, remove redundant PublicName in interpolations * Remove EntityFrameworkCorePomeloVersion property (stable release is available now), fix flaky tests on MySQL
1 parent 5eddc99 commit 5f85f93

29 files changed

+248
-65
lines changed

package-versions.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
<!-- Non-published dependencies (these are safe to update, won't cause a breaking change) -->
4141
<AspNetCoreVersion>9.0.*</AspNetCoreVersion>
4242
<EntityFrameworkCoreVersion>9.0.*</EntityFrameworkCoreVersion>
43-
<EntityFrameworkCorePomeloVersion>9.0.0-*</EntityFrameworkCorePomeloVersion>
4443
</PropertyGroup>
4544

4645
<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
@@ -50,6 +49,5 @@
5049
<!-- Non-published dependencies (these are safe to update, won't cause a breaking change) -->
5150
<AspNetCoreVersion>8.0.*</AspNetCoreVersion>
5251
<EntityFrameworkCoreVersion>8.0.*</EntityFrameworkCoreVersion>
53-
<EntityFrameworkCorePomeloVersion>$(EntityFrameworkCoreVersion)</EntityFrameworkCorePomeloVersion>
5452
</PropertyGroup>
5553
</Project>

src/Examples/DapperExample/DapperExample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="$(EntityFrameworkCoreVersion)" />
1717
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(EntityFrameworkCoreVersion)" />
1818
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(EntityFrameworkCoreVersion)" />
19-
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="$(EntityFrameworkCorePomeloVersion)" />
19+
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="$(EntityFrameworkCoreVersion)" />
2020
</ItemGroup>
2121
</Project>

src/Examples/DapperExample/TranslationToSql/Builders/SelectStatementBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ public override SqlTreeNode VisitResourceFieldChain(ResourceFieldChainExpression
552552
throw new JsonApiException(new ErrorObject(HttpStatusCode.BadRequest)
553553
{
554554
Title = "Sorting or filtering on the requested attribute is unavailable.",
555-
Detail = $"Sorting or filtering on attribute '{attribute.PublicName}' is unavailable because it is unmapped."
555+
Detail = $"Sorting or filtering on attribute '{attribute}' is unavailable because it is unmapped."
556556
});
557557
}
558558

src/JsonApiDotNetCore.Annotations/Resources/Annotations/ResourceFieldAttribute.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ protected void AssertIsIdentifiable(object? resource)
129129
return _publicName ?? (_property != null ? _property.Name : base.ToString());
130130
}
131131

132+
public string ToFullString()
133+
{
134+
return $"{_type?.PublicName}:{ToString()}";
135+
}
136+
132137
/// <inheritdoc />
133138
public override bool Equals(object? obj)
134139
{

src/JsonApiDotNetCore/Configuration/ResourceGraphBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private static void ValidateAttributesInDerivedType(ResourceType resourceType)
130130
if (resourceType.FindAttributeByPublicName(attribute.PublicName) == null)
131131
{
132132
throw new InvalidConfigurationException(
133-
$"Attribute '{attribute.PublicName}' from base type '{resourceType.BaseType.ClrType}' does not exist in derived type '{resourceType.ClrType}'.");
133+
$"Attribute '{attribute}' from base type '{resourceType.BaseType.ClrType}' does not exist in derived type '{resourceType.ClrType}'.");
134134
}
135135
}
136136
}
@@ -142,7 +142,7 @@ private static void ValidateRelationshipsInDerivedType(ResourceType resourceType
142142
if (resourceType.FindRelationshipByPublicName(relationship.PublicName) == null)
143143
{
144144
throw new InvalidConfigurationException(
145-
$"Relationship '{relationship.PublicName}' from base type '{resourceType.BaseType.ClrType}' does not exist in derived type '{resourceType.ClrType}'.");
145+
$"Relationship '{relationship}' from base type '{resourceType.BaseType.ClrType}' does not exist in derived type '{resourceType.ClrType}'.");
146146
}
147147
}
148148
}

src/JsonApiDotNetCore/Queries/Expressions/AnyExpression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ private string InnerToString(bool toFullString)
5656

5757
builder.Append(Keywords.Any);
5858
builder.Append('(');
59-
builder.Append(toFullString ? TargetAttribute.ToFullString() : TargetAttribute);
59+
builder.Append(toFullString ? TargetAttribute.ToFullString() : TargetAttribute.ToString());
6060
builder.Append(',');
61-
builder.Append(string.Join(",", Constants.Select(constant => toFullString ? constant.ToFullString() : constant.ToString()).OrderBy(value => value)));
61+
builder.Append(string.Join(',', Constants.Select(constant => toFullString ? constant.ToFullString() : constant.ToString()).OrderBy(value => value)));
6262
builder.Append(')');
6363

6464
return builder.ToString();

src/JsonApiDotNetCore/Queries/Expressions/HasExpression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ private string InnerToString(bool toFullString)
5858
var builder = new StringBuilder();
5959
builder.Append(Keywords.Has);
6060
builder.Append('(');
61-
builder.Append(toFullString ? TargetCollection.ToFullString() : TargetCollection);
61+
builder.Append(toFullString ? TargetCollection.ToFullString() : TargetCollection.ToString());
6262

6363
if (Filter != null)
6464
{
6565
builder.Append(',');
66-
builder.Append(toFullString ? Filter.ToFullString() : Filter);
66+
builder.Append(toFullString ? Filter.ToFullString() : Filter.ToString());
6767
}
6868

6969
builder.Append(')');

src/JsonApiDotNetCore/Queries/Expressions/IncludeElementExpression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ public override string ToFullString()
5757
private string InnerToString(bool toFullString)
5858
{
5959
var builder = new StringBuilder();
60-
builder.Append(toFullString ? $"{Relationship.LeftType.PublicName}:{Relationship.PublicName}" : Relationship.PublicName);
60+
builder.Append(toFullString ? $"{Relationship.LeftType}:{Relationship}" : Relationship.ToString());
6161

6262
if (Children.Count > 0)
6363
{
6464
builder.Append('{');
65-
builder.Append(string.Join(",", Children.Select(child => toFullString ? child.ToFullString() : child.ToString()).OrderBy(name => name)));
65+
builder.Append(string.Join(',', Children.Select(child => toFullString ? child.ToFullString() : child.ToString()).OrderBy(name => name)));
6666
builder.Append('}');
6767
}
6868

src/JsonApiDotNetCore/Queries/Expressions/IncludeExpression.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public override string ToFullString()
5050
private string InnerToString(bool toFullString)
5151
{
5252
IReadOnlyCollection<ResourceFieldChainExpression> chains = IncludeChainConverter.Instance.GetRelationshipChains(this);
53-
return string.Join(",", chains.Select(field => toFullString ? field.ToFullString() : field.ToString()).Distinct().OrderBy(name => name));
53+
return string.Join(',', chains.Select(field => toFullString ? field.ToFullString() : field.ToString()).Distinct().OrderBy(name => name));
5454
}
5555

5656
public override bool Equals(object? obj)

src/JsonApiDotNetCore/Queries/Expressions/IsTypeExpression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private string InnerToString(bool toFullString)
7171

7272
if (TargetToOneRelationship != null)
7373
{
74-
builder.Append(toFullString ? TargetToOneRelationship.ToFullString() : TargetToOneRelationship);
74+
builder.Append(toFullString ? TargetToOneRelationship.ToFullString() : TargetToOneRelationship.ToString());
7575
}
7676

7777
builder.Append(',');
@@ -80,7 +80,7 @@ private string InnerToString(bool toFullString)
8080
if (Child != null)
8181
{
8282
builder.Append(',');
83-
builder.Append(toFullString ? Child.ToFullString() : Child);
83+
builder.Append(toFullString ? Child.ToFullString() : Child.ToString());
8484
}
8585

8686
builder.Append(')');

0 commit comments

Comments
 (0)