Skip to content

Commit

Permalink
Add complex types to Metadata
Browse files Browse the repository at this point in the history
Part of #13947
  • Loading branch information
AndriySvyryd authored Jun 27, 2023
1 parent a74747f commit 5ef57c1
Show file tree
Hide file tree
Showing 340 changed files with 24,162 additions and 6,714 deletions.
3 changes: 3 additions & 0 deletions EFCore.Runtime.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"src\\EFCore.InMemory\\EFCore.InMemory.csproj",
"src\\EFCore.Proxies\\EFCore.Proxies.csproj",
"src\\EFCore.Relational\\EFCore.Relational.csproj",
"src\\EFCore.SqlServer.Abstractions\\EFCore.SqlServer.Abstractions.csproj",
"src\\EFCore.SqlServer.HierarchyId\\EFCore.SqlServer.HierarchyId.csproj",
"src\\EFCore.SqlServer.NTS\\EFCore.SqlServer.NTS.csproj",
"src\\EFCore.SqlServer\\EFCore.SqlServer.csproj",
"src\\EFCore.Sqlite.Core\\EFCore.Sqlite.Core.csproj",
Expand All @@ -33,6 +35,7 @@
"test\\EFCore.Relational.Tests\\EFCore.Relational.Tests.csproj",
"test\\EFCore.Specification.Tests\\EFCore.Specification.Tests.csproj",
"test\\EFCore.SqlServer.FunctionalTests\\EFCore.SqlServer.FunctionalTests.csproj",
"test\\EFCore.SqlServer.HierarchyId.Tests\\EFCore.SqlServer.HierarchyId.Tests.csproj",
"test\\EFCore.SqlServer.Tests\\EFCore.SqlServer.Tests.csproj",
"test\\EFCore.Sqlite.FunctionalTests\\EFCore.Sqlite.FunctionalTests.csproj",
"test\\EFCore.Sqlite.Tests\\EFCore.Sqlite.Tests.csproj",
Expand Down
7 changes: 4 additions & 3 deletions src/EFCore.Cosmos/Extensions/CosmosPropertyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore.Cosmos.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Internal;

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

private static string GetDefaultJsonPropertyName(IReadOnlyProperty property)
{
var entityType = property.DeclaringEntityType;
var ownership = entityType.FindOwnership();
var entityType = property.DeclaringType as IEntityType;
var ownership = entityType?.FindOwnership();

if (ownership != null
&& !entityType.IsDocumentRoot())
&& !entityType!.IsDocumentRoot())
{
var pk = property.FindContainingPrimaryKey();
if (pk != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ public virtual void ProcessEntityTypeAnnotationChanged(
/// <returns>The store value generation strategy to set for the given property.</returns>
protected override ValueGenerated? GetValueGenerated(IConventionProperty property)
{
var entityType = property.DeclaringEntityType;
var entityType = property.DeclaringType as IConventionEntityType;
var propertyType = property.ClrType.UnwrapNullableType();
if (propertyType == typeof(int))
if (propertyType == typeof(int)
&& entityType != null)
{
var ownership = entityType.FindOwnership();
if (ownership is { IsUnique: false }
Expand Down
6 changes: 3 additions & 3 deletions src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ public virtual void ProcessPropertyAnnotationChanged(
&& (string?)annotation?.Value == IdPropertyJsonName
&& propertyBuilder.Metadata.Name != DefaultIdPropertyName)
{
var entityType = propertyBuilder.Metadata.DeclaringEntityType;
var declaringType = propertyBuilder.Metadata.DeclaringType;

var idProperty = entityType.FindProperty(DefaultIdPropertyName);
var idProperty = declaringType.FindProperty(DefaultIdPropertyName);
if (idProperty != null)
{
foreach (var key in idProperty.GetContainingKeys().ToList())
Expand All @@ -306,7 +306,7 @@ public virtual void ProcessPropertyAnnotationChanged(
}
}

ProcessIdProperty(entityType.Builder);
ProcessIdProperty(declaringType.FundamentalEntityType.Builder);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class CosmosPropertyExtensions
public static bool IsOrdinalKeyProperty(this IReadOnlyProperty property)
{
Check.DebugAssert(
property.DeclaringEntityType.IsOwned(), $"Expected {property.DeclaringEntityType.DisplayName()} to be owned.");
(property.DeclaringType as IEntityType)?.IsOwned() == true, $"Expected {property.DeclaringType.DisplayName()} to be owned.");
Check.DebugAssert(property.GetJsonPropertyName().Length == 0, $"Expected {property.Name} to be non-persisted.");

return property.FindContainingPrimaryKey() is IReadOnlyKey { Properties.Count: > 1 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,13 @@ private Expression CreateGetValueExpression(
var storeName = property.GetJsonPropertyName();
if (storeName.Length == 0)
{
var entityType = property.DeclaringEntityType;
if (!entityType.IsDocumentRoot())
var entityType = property.DeclaringType as IEntityType;
if (entityType == null
|| !entityType.IsDocumentRoot())
{
var ownership = entityType.FindOwnership();
if (!ownership.IsUnique
var ownership = entityType?.FindOwnership();
if (ownership != null
&& !ownership.IsUnique
&& property.IsOrdinalKeyProperty())
{
var readExpression = _ordinalParameterBindings[jObjectExpression];
Expand All @@ -621,8 +623,8 @@ private Expression CreateGetValueExpression(
if (_ownerMappings.TryGetValue(jObjectExpression, out var ownerInfo))
{
Check.DebugAssert(
principalProperty.DeclaringEntityType.IsAssignableFrom(ownerInfo.EntityType),
$"{principalProperty.DeclaringEntityType} is not assignable from {ownerInfo.EntityType}");
principalProperty.DeclaringType.IsAssignableFrom(ownerInfo.EntityType),
$"{principalProperty.DeclaringType} is not assignable from {ownerInfo.EntityType}");

ownerJObjectExpression = ownerInfo.JObjectExpression;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public virtual Expression Update(Expression accessExpression)
/// </summary>
public virtual Expression BindProperty(IProperty property, bool clientEval)
{
if (!EntityType.IsAssignableFrom(property.DeclaringEntityType)
&& !property.DeclaringEntityType.IsAssignableFrom(EntityType))
if (!EntityType.IsAssignableFrom(property.DeclaringType)
&& !property.DeclaringType.IsAssignableFrom(EntityType))
{
throw new InvalidOperationException(
CosmosStrings.UnableToBindMemberToEntityProjection("property", property.Name, EntityType.DisplayName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ namespace Microsoft.EntityFrameworkCore.Cosmos.ValueGeneration;
public class IdValueGeneratorFactory : ValueGeneratorFactory
{
/// <inheritdoc />
public override ValueGenerator Create(IProperty property, IEntityType entityType)
public override ValueGenerator Create(IProperty property, ITypeBase entityType)
=> new IdValueGenerator();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public CosmosValueGeneratorSelector(ValueGeneratorSelectorDependencies dependenc
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override ValueGenerator? FindForType(IProperty property, IEntityType entityType, Type clrType)
protected override ValueGenerator? FindForType(IProperty property, ITypeBase typeBase, Type clrType)
{
if (property.GetJsonPropertyName() == ""
&& clrType == typeof(int))
{
return new TemporaryNumberValueGeneratorFactory().Create(property, entityType);
return new TemporaryNumberValueGeneratorFactory().Create(property, typeBase);
}

return base.FindForType(property, entityType, clrType);
return base.FindForType(property, typeBase, clrType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private static void UpdateOwnedTypes(IMutableEntityType entityType)
if (oldProperty is IConventionProperty conventionProperty
&& conventionProperty.GetConfigurationSource() == ConfigurationSource.Convention)
{
oldProperty.DeclaringEntityType.RemoveProperty(oldProperty);
oldProperty.DeclaringType.RemoveProperty(oldProperty);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore.Design/Properties/DesignStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/EFCore.Design/Properties/DesignStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@
<value>Entity Framework Core Migrations Bundle</value>
</data>
<data name="CannotCreateContextInstance" xml:space="preserve">
Unable to create a 'DbContext' of type '{contextType}'. The exception '{rootException}' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
<value>Unable to create a 'DbContext' of type '{contextType}'. The exception '{rootException}' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728</value>
</data>
<data name="CannotFindDbContextTypes" xml:space="preserve">
The exception '{rootException}' was thrown while attempting to find 'DbContext' types. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
<value>The exception '{rootException}' was thrown while attempting to find 'DbContext' types. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728</value>
</data>
<data name="CannotFindDesignTimeProviderAssemblyAttribute" xml:space="preserve">
<value>Unable to find expected assembly attribute [DesignTimeProviderServices] in provider assembly '{runtimeProviderAssemblyName}'. This attribute is required to identify the class which acts as the design-time service provider factory for the provider.</value>
Expand Down Expand Up @@ -381,7 +381,7 @@ Change your target project to the migrations project by using the Package Manage
<value>The migration '{name}' has already been applied to the database. Revert it and try again. If the migration has been applied to other databases, consider reverting its changes using a new migration instead.</value>
</data>
<data name="SensitiveInformationWarning" xml:space="preserve">
<value>To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.</value>
<value>To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.</value>
<comment>Localize the URL if we have localized docs.</comment>
</data>
<data name="SequencesRequireName" xml:space="preserve">
Expand Down Expand Up @@ -441,4 +441,4 @@ Change your target project to the migrations project by using the Package Manage
<data name="WritingSnapshot" xml:space="preserve">
<value>Writing model snapshot to '{file}'.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public virtual string TransformText()
if (!Options.SuppressConnectionStringWarning)
{

this.Write(@"#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
this.Write(@"#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
");

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public partial class <#= Options.ContextName #> : DbContext
if (!Options.SuppressConnectionStringWarning)
{
#>
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see https://go.microsoft.com/fwlink/?LinkId=723263.
<#
}
#>
Expand Down
Loading

0 comments on commit 5ef57c1

Please sign in to comment.