Skip to content

Commit 5ef57c1

Browse files
authored
Add complex types to Metadata
Part of #13947
1 parent a74747f commit 5ef57c1

File tree

340 files changed

+24162
-6714
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

340 files changed

+24162
-6714
lines changed

EFCore.Runtime.slnf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"src\\EFCore.InMemory\\EFCore.InMemory.csproj",
1010
"src\\EFCore.Proxies\\EFCore.Proxies.csproj",
1111
"src\\EFCore.Relational\\EFCore.Relational.csproj",
12+
"src\\EFCore.SqlServer.Abstractions\\EFCore.SqlServer.Abstractions.csproj",
13+
"src\\EFCore.SqlServer.HierarchyId\\EFCore.SqlServer.HierarchyId.csproj",
1214
"src\\EFCore.SqlServer.NTS\\EFCore.SqlServer.NTS.csproj",
1315
"src\\EFCore.SqlServer\\EFCore.SqlServer.csproj",
1416
"src\\EFCore.Sqlite.Core\\EFCore.Sqlite.Core.csproj",
@@ -33,6 +35,7 @@
3335
"test\\EFCore.Relational.Tests\\EFCore.Relational.Tests.csproj",
3436
"test\\EFCore.Specification.Tests\\EFCore.Specification.Tests.csproj",
3537
"test\\EFCore.SqlServer.FunctionalTests\\EFCore.SqlServer.FunctionalTests.csproj",
38+
"test\\EFCore.SqlServer.HierarchyId.Tests\\EFCore.SqlServer.HierarchyId.Tests.csproj",
3639
"test\\EFCore.SqlServer.Tests\\EFCore.SqlServer.Tests.csproj",
3740
"test\\EFCore.Sqlite.FunctionalTests\\EFCore.Sqlite.FunctionalTests.csproj",
3841
"test\\EFCore.Sqlite.Tests\\EFCore.Sqlite.Tests.csproj",

src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;
5+
using Microsoft.EntityFrameworkCore.Metadata.Internal;
56

67
// ReSharper disable once CheckNamespace
78
namespace Microsoft.EntityFrameworkCore;
@@ -26,11 +27,11 @@ public static string GetJsonPropertyName(this IReadOnlyProperty property)
2627

2728
private static string GetDefaultJsonPropertyName(IReadOnlyProperty property)
2829
{
29-
var entityType = property.DeclaringEntityType;
30-
var ownership = entityType.FindOwnership();
30+
var entityType = property.DeclaringType as IEntityType;
31+
var ownership = entityType?.FindOwnership();
3132

3233
if (ownership != null
33-
&& !entityType.IsDocumentRoot())
34+
&& !entityType!.IsDocumentRoot())
3435
{
3536
var pk = property.FindContainingPrimaryKey();
3637
if (pk != null

src/EFCore.Cosmos/Metadata/Conventions/CosmosValueGenerationConvention.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ public virtual void ProcessEntityTypeAnnotationChanged(
6767
/// <returns>The store value generation strategy to set for the given property.</returns>
6868
protected override ValueGenerated? GetValueGenerated(IConventionProperty property)
6969
{
70-
var entityType = property.DeclaringEntityType;
70+
var entityType = property.DeclaringType as IConventionEntityType;
7171
var propertyType = property.ClrType.UnwrapNullableType();
72-
if (propertyType == typeof(int))
72+
if (propertyType == typeof(int)
73+
&& entityType != null)
7374
{
7475
var ownership = entityType.FindOwnership();
7576
if (ownership is { IsUnique: false }

src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ public virtual void ProcessPropertyAnnotationChanged(
295295
&& (string?)annotation?.Value == IdPropertyJsonName
296296
&& propertyBuilder.Metadata.Name != DefaultIdPropertyName)
297297
{
298-
var entityType = propertyBuilder.Metadata.DeclaringEntityType;
298+
var declaringType = propertyBuilder.Metadata.DeclaringType;
299299

300-
var idProperty = entityType.FindProperty(DefaultIdPropertyName);
300+
var idProperty = declaringType.FindProperty(DefaultIdPropertyName);
301301
if (idProperty != null)
302302
{
303303
foreach (var key in idProperty.GetContainingKeys().ToList())
@@ -306,7 +306,7 @@ public virtual void ProcessPropertyAnnotationChanged(
306306
}
307307
}
308308

309-
ProcessIdProperty(entityType.Builder);
309+
ProcessIdProperty(declaringType.FundamentalEntityType.Builder);
310310
}
311311
}
312312
}

src/EFCore.Cosmos/Metadata/Internal/CosmosPropertyExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static class CosmosPropertyExtensions
2020
public static bool IsOrdinalKeyProperty(this IReadOnlyProperty property)
2121
{
2222
Check.DebugAssert(
23-
property.DeclaringEntityType.IsOwned(), $"Expected {property.DeclaringEntityType.DisplayName()} to be owned.");
23+
(property.DeclaringType as IEntityType)?.IsOwned() == true, $"Expected {property.DeclaringType.DisplayName()} to be owned.");
2424
Check.DebugAssert(property.GetJsonPropertyName().Length == 0, $"Expected {property.Name} to be non-persisted.");
2525

2626
return property.FindContainingPrimaryKey() is IReadOnlyKey { Properties.Count: > 1 }

src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.CosmosProjectionBindingRemovingExpressionVisitorBase.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -598,11 +598,13 @@ private Expression CreateGetValueExpression(
598598
var storeName = property.GetJsonPropertyName();
599599
if (storeName.Length == 0)
600600
{
601-
var entityType = property.DeclaringEntityType;
602-
if (!entityType.IsDocumentRoot())
601+
var entityType = property.DeclaringType as IEntityType;
602+
if (entityType == null
603+
|| !entityType.IsDocumentRoot())
603604
{
604-
var ownership = entityType.FindOwnership();
605-
if (!ownership.IsUnique
605+
var ownership = entityType?.FindOwnership();
606+
if (ownership != null
607+
&& !ownership.IsUnique
606608
&& property.IsOrdinalKeyProperty())
607609
{
608610
var readExpression = _ordinalParameterBindings[jObjectExpression];
@@ -621,8 +623,8 @@ private Expression CreateGetValueExpression(
621623
if (_ownerMappings.TryGetValue(jObjectExpression, out var ownerInfo))
622624
{
623625
Check.DebugAssert(
624-
principalProperty.DeclaringEntityType.IsAssignableFrom(ownerInfo.EntityType),
625-
$"{principalProperty.DeclaringEntityType} is not assignable from {ownerInfo.EntityType}");
626+
principalProperty.DeclaringType.IsAssignableFrom(ownerInfo.EntityType),
627+
$"{principalProperty.DeclaringType} is not assignable from {ownerInfo.EntityType}");
626628

627629
ownerJObjectExpression = ownerInfo.JObjectExpression;
628630
}

src/EFCore.Cosmos/Query/Internal/EntityProjectionExpression.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public virtual Expression Update(Expression accessExpression)
101101
/// </summary>
102102
public virtual Expression BindProperty(IProperty property, bool clientEval)
103103
{
104-
if (!EntityType.IsAssignableFrom(property.DeclaringEntityType)
105-
&& !property.DeclaringEntityType.IsAssignableFrom(EntityType))
104+
if (!EntityType.IsAssignableFrom(property.DeclaringType)
105+
&& !property.DeclaringType.IsAssignableFrom(EntityType))
106106
{
107107
throw new InvalidOperationException(
108108
CosmosStrings.UnableToBindMemberToEntityProjection("property", property.Name, EntityType.DisplayName()));

src/EFCore.Cosmos/ValueGeneration/IdValueGeneratorFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.ValueGeneration;
1515
public class IdValueGeneratorFactory : ValueGeneratorFactory
1616
{
1717
/// <inheritdoc />
18-
public override ValueGenerator Create(IProperty property, IEntityType entityType)
18+
public override ValueGenerator Create(IProperty property, ITypeBase entityType)
1919
=> new IdValueGenerator();
2020
}

src/EFCore.Cosmos/ValueGeneration/Internal/CosmosValueGeneratorSelector.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ public CosmosValueGeneratorSelector(ValueGeneratorSelectorDependencies dependenc
2828
/// any release. You should only use it directly in your code with extreme caution and knowing that
2929
/// doing so can result in application failures when updating to a new Entity Framework Core release.
3030
/// </summary>
31-
protected override ValueGenerator? FindForType(IProperty property, IEntityType entityType, Type clrType)
31+
protected override ValueGenerator? FindForType(IProperty property, ITypeBase typeBase, Type clrType)
3232
{
3333
if (property.GetJsonPropertyName() == ""
3434
&& clrType == typeof(int))
3535
{
36-
return new TemporaryNumberValueGeneratorFactory().Create(property, entityType);
36+
return new TemporaryNumberValueGeneratorFactory().Create(property, typeBase);
3737
}
3838

39-
return base.FindForType(property, entityType, clrType);
39+
return base.FindForType(property, typeBase, clrType);
4040
}
4141
}

src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private static void UpdateOwnedTypes(IMutableEntityType entityType)
185185
if (oldProperty is IConventionProperty conventionProperty
186186
&& conventionProperty.GetConfigurationSource() == ConfigurationSource.Convention)
187187
{
188-
oldProperty.DeclaringEntityType.RemoveProperty(oldProperty);
188+
oldProperty.DeclaringType.RemoveProperty(oldProperty);
189189
}
190190
}
191191
}

0 commit comments

Comments
 (0)