Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1250,9 +1250,7 @@ public static void SetComment(this IMutableProperty property, string? comment)
/// <param name="property">The property.</param>
/// <returns>The collation for the column this property is mapped to.</returns>
public static string? GetCollation(this IReadOnlyProperty property)
=> (property is RuntimeProperty)
? throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData)
: (string?)property.FindAnnotation(RelationalAnnotationNames.Collation)?.Value;
=> (string?)property.FindAnnotation(RelationalAnnotationNames.Collation)?.Value;

/// <summary>
/// Returns the collation to be used for the column.
Expand All @@ -1262,11 +1260,6 @@ public static void SetComment(this IMutableProperty property, string? comment)
/// <returns>The collation for the column this property is mapped to.</returns>
public static string? GetCollation(this IReadOnlyProperty property, in StoreObjectIdentifier storeObject)
{
if (property is RuntimeProperty)
{
throw new InvalidOperationException(CoreStrings.RuntimeModelMissingData);
}

var annotation = property.FindAnnotation(RelationalAnnotationNames.Collation);
return annotation != null
? (string?)annotation.Value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public override void Generate(IProperty property, CSharpRuntimeAnnotationCodeGen
{
annotations[SqlServerAnnotationNames.ValueGenerationStrategy] = property.GetValueGenerationStrategy();
}

if (!annotations.ContainsKey(RelationalAnnotationNames.Collation))
{
annotations[RelationalAnnotationNames.Collation] = property.GetCollation();
}
}

base.Generate(property, parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ protected override void ProcessPropertyAnnotations(
{
annotations[SqlServerAnnotationNames.ValueGenerationStrategy] = property.GetValueGenerationStrategy();
}

if (!annotations.ContainsKey(RelationalAnnotationNames.Collation))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use TryAdd (here and elsewhere)

{
annotations[RelationalAnnotationNames.Collation] = property.GetCollation();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,12 +767,15 @@ private void AppendDeclareTable(
private static string GetTypeNameForCopy(IProperty property)
{
var typeName = property.GetColumnType();
var collation = property[RelationalAnnotationNames.Collation]?.ToString();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var collation = property[RelationalAnnotationNames.Collation]?.ToString();
var collation = property.GetCollation();


return property.ClrType == typeof(byte[])
typeName = property.ClrType == typeof(byte[])
&& (typeName.Equals("rowversion", StringComparison.OrdinalIgnoreCase)
|| typeName.Equals("timestamp", StringComparison.OrdinalIgnoreCase))
? property.IsNullable ? "varbinary(8)" : "binary(8)"
: typeName;

return collation is null ? typeName : $"{typeName} COLLATE {collation}";
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1904,9 +1904,6 @@ public static void CreateAnnotations(RuntimeEntityType runtimeEntityType)
CoreStrings.RuntimeModelMissingData,
Assert.Throws<InvalidOperationException>(() => detailsProperty.IsSparse()).Message);
Assert.Null(detailsProperty[RelationalAnnotationNames.Collation]);
Assert.Equal(
CoreStrings.RuntimeModelMissingData,
Assert.Throws<InvalidOperationException>(() => detailsProperty.GetCollation()).Message);

var ownedFragment = referenceOwnedType.GetMappingFragments().Single();
Assert.Equal(nameof(OwnedType.Details), detailsProperty.GetColumnName(ownedFragment.StoreObject));
Expand Down