Skip to content

Commit 9d0a4e1

Browse files
committed
Review tweaks
1 parent 6330937 commit 9d0a4e1

File tree

15 files changed

+291
-54
lines changed

15 files changed

+291
-54
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore;
5+
6+
/// <summary>
7+
/// SQLite-specific extension methods for <see cref="ComplexTypePrimitiveCollectionBuilder" />.
8+
/// </summary>
9+
/// <remarks>
10+
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and
11+
/// <see href="https://aka.ms/efcore-docs-sqlite">Accessing SQLite databases with EF Core</see> for more information and examples.
12+
/// </remarks>
13+
public static class SqliteComplexTypePrimitiveCollectionBuilderExtensions
14+
{
15+
/// <summary>
16+
/// Configures the SRID of the column that the property maps to when targeting SQLite.
17+
/// </summary>
18+
/// <remarks>
19+
/// See <see href="https://aka.ms/efcore-docs-spatial">Spatial data</see>, and
20+
/// <see href="https://aka.ms/efcore-docs-sqlite">Accessing SQLite databases with EF Core</see> for more information and examples.
21+
/// </remarks>
22+
/// <param name="primitiveCollectionBuilder">The builder for the property being configured.</param>
23+
/// <param name="srid">The SRID.</param>
24+
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
25+
public static ComplexTypePrimitiveCollectionBuilder HasSrid(
26+
this ComplexTypePrimitiveCollectionBuilder primitiveCollectionBuilder,
27+
int srid)
28+
{
29+
primitiveCollectionBuilder.Metadata.SetSrid(srid);
30+
31+
return primitiveCollectionBuilder;
32+
}
33+
34+
/// <summary>
35+
/// Configures the SRID of the column that the property maps to when targeting SQLite.
36+
/// </summary>
37+
/// <remarks>
38+
/// See <see href="https://aka.ms/efcore-docs-spatial">Spatial data</see>, and
39+
/// <see href="https://aka.ms/efcore-docs-sqlite">Accessing SQLite databases with EF Core</see> for more information and examples.
40+
/// </remarks>
41+
/// <param name="primitiveCollectionBuilder">The builder for the property being configured.</param>
42+
/// <param name="srid">The SRID.</param>
43+
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
44+
public static ComplexTypePrimitiveCollectionBuilder<TProperty> HasSrid<TProperty>(
45+
this ComplexTypePrimitiveCollectionBuilder<TProperty> primitiveCollectionBuilder,
46+
int srid)
47+
=> (ComplexTypePrimitiveCollectionBuilder<TProperty>)HasSrid(
48+
(ComplexTypePrimitiveCollectionBuilder)primitiveCollectionBuilder, srid);
49+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.EntityFrameworkCore;
5+
6+
/// <summary>
7+
/// SQLite-specific extension methods for <see cref="ComplexTypePropertyBuilder" />.
8+
/// </summary>
9+
/// <remarks>
10+
/// See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and
11+
/// <see href="https://aka.ms/efcore-docs-sqlite">Accessing SQLite databases with EF Core</see> for more information and examples.
12+
/// </remarks>
13+
public static class SqliteComplexTypePropertyBuilderExtensions
14+
{
15+
/// <summary>
16+
/// Configures the SRID of the column that the property maps to when targeting SQLite.
17+
/// </summary>
18+
/// <remarks>
19+
/// See <see href="https://aka.ms/efcore-docs-spatial">Spatial data</see>, and
20+
/// <see href="https://aka.ms/efcore-docs-sqlite">Accessing SQLite databases with EF Core</see> for more information and examples.
21+
/// </remarks>
22+
/// <param name="propertyBuilder">The builder for the property being configured.</param>
23+
/// <param name="srid">The SRID.</param>
24+
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
25+
public static ComplexTypePropertyBuilder HasSrid(this ComplexTypePropertyBuilder propertyBuilder, int srid)
26+
{
27+
propertyBuilder.Metadata.SetSrid(srid);
28+
29+
return propertyBuilder;
30+
}
31+
32+
/// <summary>
33+
/// Configures the SRID of the column that the property maps to when targeting SQLite.
34+
/// </summary>
35+
/// <remarks>
36+
/// See <see href="https://aka.ms/efcore-docs-spatial">Spatial data</see>, and
37+
/// <see href="https://aka.ms/efcore-docs-sqlite">Accessing SQLite databases with EF Core</see> for more information and examples.
38+
/// </remarks>
39+
/// <param name="propertyBuilder">The builder for the property being configured.</param>
40+
/// <param name="srid">The SRID.</param>
41+
/// <returns>The same builder instance so that multiple calls can be chained.</returns>
42+
public static ComplexTypePropertyBuilder<TProperty> HasSrid<TProperty>(
43+
this ComplexTypePropertyBuilder<TProperty> propertyBuilder,
44+
int srid)
45+
=> (ComplexTypePropertyBuilder<TProperty>)HasSrid((ComplexTypePropertyBuilder)propertyBuilder, srid);
46+
}

src/EFCore/Metadata/Builders/IConventionPropertyBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,13 +545,13 @@ bool CanSetProviderValueComparer(
545545
/// any release. You should only use it directly in your code with extreme caution and knowing that
546546
/// doing so can result in application failures when updating to a new Entity Framework Core release.
547547
/// </summary>
548-
IConventionElementTypeBuilder? ElementType(bool fromDataAnnotation = false);
548+
IConventionElementTypeBuilder? ElementType(bool elementType, bool fromDataAnnotation = false);
549549

550550
/// <summary>
551551
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
552552
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
553553
/// any release. You should only use it directly in your code with extreme caution and knowing that
554554
/// doing so can result in application failures when updating to a new Entity Framework Core release.
555555
/// </summary>
556-
bool CanSetElementType(bool fromDataAnnotation = false);
556+
bool CanSetElementType(bool elementType, bool fromDataAnnotation = false);
557557
}

src/EFCore/Metadata/Conventions/PropertyDiscoveryConvention.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private void Process(IConventionEntityTypeBuilder entityTypeBuilder)
9494
var propertyBuilder = entityTypeBuilder.Property(propertyInfo);
9595
if (mapping?.ElementTypeMapping != null)
9696
{
97-
propertyBuilder?.ElementType();
97+
propertyBuilder?.ElementType(true);
9898
}
9999
}
100100
}

src/EFCore/Metadata/IConventionProperty.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ bool IsImplicitlyCreated()
466466
/// <param name="primitiveCollection">If <see langword="true"/>, then this is a collection of primitive elements.</param>
467467
/// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
468468
/// <returns>The configuration for the elements.</returns>
469-
IElementType? IsPrimitiveCollection(bool primitiveCollection, bool fromDataAnnotation = false);
469+
IElementType? ElementType(bool primitiveCollection, bool fromDataAnnotation = false);
470470

471471
/// <summary>
472472
/// Returns the configuration source for <see cref="IReadOnlyProperty.GetElementType" />.

src/EFCore/Metadata/IMutableProperty.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ void SetProviderValueComparer(
276276
/// <summary>
277277
/// Sets the configuration for elements of the primitive collection represented by this property.
278278
/// </summary>
279-
/// <param name="primitiveCollection">If <see langword="true"/>, then this is a collection of primitive elements.</param>
280-
void IsPrimitiveCollection(bool primitiveCollection);
279+
/// <param name="elementType">If <see langword="true"/>, then this is a collection of primitive elements.</param>
280+
void ElementType(bool elementType);
281281

282282
/// <inheritdoc />
283283
bool IReadOnlyProperty.IsNullable

src/EFCore/Metadata/Internal/InternalPropertyBuilder.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ public virtual bool CanSetConversion(Type? providerClrType, ConfigurationSource?
564564
{
565565
if (CanSetConverter(converterType, configurationSource))
566566
{
567-
Metadata.IsPrimitiveCollection(false, configurationSource);
567+
Metadata.ElementType(false, configurationSource);
568568
Metadata.SetProviderClrType(null, configurationSource);
569569
Metadata.SetValueConverter(converterType, configurationSource);
570570

@@ -776,11 +776,11 @@ public virtual bool CanSetProviderValueComparer(
776776
/// any release. You should only use it directly in your code with extreme caution and knowing that
777777
/// doing so can result in application failures when updating to a new Entity Framework Core release.
778778
/// </summary>
779-
public virtual InternalElementTypeBuilder? ElementType(ConfigurationSource configurationSource)
779+
public virtual InternalElementTypeBuilder? ElementType(bool elementType, ConfigurationSource configurationSource)
780780
{
781-
if (CanSetElementType(configurationSource))
781+
if (CanSetElementType(elementType, configurationSource))
782782
{
783-
Metadata.IsPrimitiveCollection(true, configurationSource);
783+
Metadata.ElementType(elementType, configurationSource);
784784
Metadata.SetValueConverter((Type?)null, configurationSource);
785785
return new InternalElementTypeBuilder((ElementType)Metadata.GetElementType()!, ModelBuilder);
786786
}
@@ -794,8 +794,9 @@ public virtual bool CanSetProviderValueComparer(
794794
/// any release. You should only use it directly in your code with extreme caution and knowing that
795795
/// doing so can result in application failures when updating to a new Entity Framework Core release.
796796
/// </summary>
797-
public virtual bool CanSetElementType(ConfigurationSource? configurationSource)
798-
=> configurationSource.Overrides(Metadata.GetElementTypeConfigurationSource());
797+
public virtual bool CanSetElementType(bool elementType, ConfigurationSource? configurationSource)
798+
=> configurationSource.Overrides(Metadata.GetElementTypeConfigurationSource())
799+
&& (elementType != (Metadata.GetElementType() != null));
799800

800801
/// <summary>
801802
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
@@ -905,10 +906,7 @@ public virtual bool CanSetElementType(ConfigurationSource? configurationSource)
905906
}
906907

907908
var oldElementType = (ElementType?)Metadata.GetElementType();
908-
var oldElementTypeConfigurationSource = Metadata.GetElementTypeConfigurationSource();
909-
if (oldElementType != null
910-
&& oldElementTypeConfigurationSource.HasValue
911-
&& newPropertyBuilder.CanSetElementType(oldElementTypeConfigurationSource))
909+
if (oldElementType != null)
912910
{
913911
var newElementType = (ElementType?)newPropertyBuilder.Metadata.GetElementType();
914912
if (newElementType != null)
@@ -1525,16 +1523,15 @@ bool IConventionPropertyBuilder.CanSetProviderValueComparer(
15251523
/// any release. You should only use it directly in your code with extreme caution and knowing that
15261524
/// doing so can result in application failures when updating to a new Entity Framework Core release.
15271525
/// </summary>
1528-
IConventionElementTypeBuilder? IConventionPropertyBuilder.ElementType(bool fromDataAnnotation)
1529-
=> ElementType(fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention);
1526+
IConventionElementTypeBuilder? IConventionPropertyBuilder.ElementType(bool elementType, bool fromDataAnnotation)
1527+
=> ElementType(elementType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention);
15301528

15311529
/// <summary>
15321530
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
15331531
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
15341532
/// any release. You should only use it directly in your code with extreme caution and knowing that
15351533
/// doing so can result in application failures when updating to a new Entity Framework Core release.
15361534
/// </summary>
1537-
public virtual bool CanSetElementType(bool fromDataAnnotation = false)
1538-
=> (fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention)
1539-
.Overrides(Metadata.GetElementTypeConfigurationSource());
1535+
bool IConventionPropertyBuilder.CanSetElementType(bool elementType, bool fromDataAnnotation)
1536+
=> CanSetElementType(elementType, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention);
15401537
}

src/EFCore/Metadata/Internal/InternalTypeBaseBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public static bool IsCompatible(MemberInfo? newMemberInfo, PropertyBase existing
333333
{
334334
var builder = Property(propertyType, propertyName, memberInfo, typeConfigurationSource, configurationSource);
335335

336-
builder?.ElementType(configurationSource!.Value);
336+
builder?.ElementType(true, configurationSource!.Value);
337337

338338
return builder;
339339
}

src/EFCore/Metadata/Internal/Property.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,26 +1214,26 @@ public virtual CoreTypeMapping? TypeMapping
12141214
/// any release. You should only use it directly in your code with extreme caution and knowing that
12151215
/// doing so can result in application failures when updating to a new Entity Framework Core release.
12161216
/// </summary>
1217-
public virtual IElementType? IsPrimitiveCollection(
1218-
bool primitiveCollection,
1217+
public virtual IElementType? ElementType(
1218+
bool elementType,
12191219
ConfigurationSource configurationSource)
12201220
{
12211221
var existingElementType = GetElementType();
12221222
if (existingElementType == null
1223-
&& primitiveCollection)
1223+
&& elementType)
12241224
{
12251225
var elementClrType = ClrType.TryGetElementType(typeof(IEnumerable<>));
12261226
if (elementClrType == null)
12271227
{
12281228
throw new InvalidOperationException(CoreStrings.NotCollection(ClrType.ShortDisplayName(), Name));
12291229
}
1230-
var elementType = new ElementType(elementClrType, this, configurationSource);
1231-
SetAnnotation(CoreAnnotationNames.ElementType, elementType, configurationSource);
1232-
OnElementTypeSet(elementType, null);
1233-
return elementType;
1230+
var newElementType = new ElementType(elementClrType, this, configurationSource);
1231+
SetAnnotation(CoreAnnotationNames.ElementType, newElementType, configurationSource);
1232+
OnElementTypeSet(newElementType, null);
1233+
return newElementType;
12341234
}
12351235

1236-
if (existingElementType != null && !primitiveCollection)
1236+
if (existingElementType != null && !elementType)
12371237
{
12381238
((ElementType)existingElementType).SetRemovedFromModel();
12391239
RemoveAnnotation(CoreAnnotationNames.ElementType);
@@ -2007,9 +2007,9 @@ void IMutableProperty.SetJsonValueReaderWriterType(Type? readerWriterType)
20072007
/// doing so can result in application failures when updating to a new Entity Framework Core release.
20082008
/// </summary>
20092009
[DebuggerStepThrough]
2010-
IElementType? IConventionProperty.IsPrimitiveCollection(bool primitiveCollection, bool fromDataAnnotation)
2011-
=> IsPrimitiveCollection(
2012-
primitiveCollection,
2010+
IElementType? IConventionProperty.ElementType(bool elementType, bool fromDataAnnotation)
2011+
=> ElementType(
2012+
elementType,
20132013
fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention);
20142014

20152015
/// <summary>
@@ -2019,6 +2019,6 @@ void IMutableProperty.SetJsonValueReaderWriterType(Type? readerWriterType)
20192019
/// doing so can result in application failures when updating to a new Entity Framework Core release.
20202020
/// </summary>
20212021
[DebuggerStepThrough]
2022-
void IMutableProperty.IsPrimitiveCollection(bool primitiveCollection)
2023-
=> IsPrimitiveCollection(primitiveCollection, ConfigurationSource.Explicit);
2022+
void IMutableProperty.ElementType(bool elementType)
2023+
=> ElementType(elementType, ConfigurationSource.Explicit);
20242024
}

test/EFCore.Cosmos.FunctionalTests/CosmosApiConsistencyTest.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,6 @@ public override
6868
typeof(CosmosPropertyBuilderExtensions),
6969
null
7070
)
71-
},
72-
{
73-
typeof(IReadOnlyElementType),
74-
(
75-
null,
76-
null,
77-
null,
78-
typeof(CosmosPrimitiveCollectionBuilderExtensions),
79-
null
80-
)
8171
}
8272
};
8373
}

0 commit comments

Comments
 (0)