Skip to content

Commit

Permalink
cleanup and some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smitpatel committed Jul 9, 2020
1 parent bcf60ef commit 9a7f5e7
Show file tree
Hide file tree
Showing 25 changed files with 185 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/EFCore/DbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private IEntityFinder Finder(Type type)

if (Model.IsShared(type))
{
throw new InvalidOperationException("Invalid");
throw new InvalidOperationException(CoreStrings.InvalidSetSharedType(type.ShortDisplayName()));
}

throw new InvalidOperationException(CoreStrings.InvalidSetType(type.ShortDisplayName()));
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/Extensions/ModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ public static bool HasEntityTypeWithDefiningNavigation([NotNull] this IModel mod
.HasEntityTypeWithDefiningNavigation(Check.NotNull(name, nameof(name)));

/// <summary>
/// Gets whether the CLR type is used by shared entities in the model.
/// Gets whether the CLR type is used by shared type entities in the model.
/// </summary>
/// <param name="model"> The model to find the entity type in. </param>
/// <param name="clrType"> The CLR type. </param>
/// <returns> Whether the CLR type is used by shared entities in the model. </returns>
/// <returns> Whether the CLR type is used by shared type entities in the model. </returns>
[DebuggerStepThrough]
public static bool IsShared([NotNull] this IModel model, [NotNull] Type clrType)
=> Check.NotNull(model, nameof(model)).AsModel().IsShared(Check.NotNull(clrType, nameof(clrType)));
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Internal/InternalDbSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private IEntityType EntityType

if (_context.Model.IsShared(typeof(TEntity)))
{
throw new InvalidOperationException("Invalid entity");
throw new InvalidOperationException(CoreStrings.InvalidSetSharedType(typeof(TEntity).ShortDisplayName()));
}

throw new InvalidOperationException(CoreStrings.InvalidSetType(typeof(TEntity).ShortDisplayName()));
Expand Down
8 changes: 4 additions & 4 deletions src/EFCore/Metadata/Builders/CollectionCollectionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,18 @@ public virtual EntityTypeBuilder UsingEntity(
/// <summary>
/// Configures the relationships to the entity types participating in the many-to-many relationship.
/// </summary>
/// <param name="joinEntityTypeName"> The name of the join entity. </param>
/// <param name="joinEntityName"> The name of the join entity. </param>
/// <param name="joinEntityType"> The CLR type of the join entity. </param>
/// <param name="configureRight"> The configuration for the relationship to the right entity type. </param>
/// <param name="configureLeft"> The configuration for the relationship to the left entity type. </param>
/// <returns> The builder for the association type. </returns>
public virtual EntityTypeBuilder UsingEntity(
[NotNull] string joinEntityTypeName,
[NotNull] string joinEntityName,
[NotNull] Type joinEntityType,
[NotNull] Func<EntityTypeBuilder, ReferenceCollectionBuilder> configureRight,
[NotNull] Func<EntityTypeBuilder, ReferenceCollectionBuilder> configureLeft)
{
Check.NotEmpty(joinEntityTypeName, nameof(joinEntityTypeName));
Check.NotEmpty(joinEntityName, nameof(joinEntityName));
Check.NotNull(joinEntityType, nameof(joinEntityType));
Check.NotNull(configureRight, nameof(configureRight));
Check.NotNull(configureLeft, nameof(configureLeft));
Expand All @@ -156,7 +156,7 @@ public virtual EntityTypeBuilder UsingEntity(
}

var entityTypeBuilder = new EntityTypeBuilder(
ModelBuilder.Entity(joinEntityTypeName, joinEntityType, ConfigurationSource.Explicit).Metadata);
ModelBuilder.Entity(joinEntityName, joinEntityType, ConfigurationSource.Explicit).Metadata);

var leftForeignKey = configureLeft(entityTypeBuilder).Metadata;
var rightForeignKey = configureRight(entityTypeBuilder).Metadata;
Expand Down
8 changes: 4 additions & 4 deletions src/EFCore/Metadata/Builders/CollectionCollectionBuilder`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ public virtual EntityTypeBuilder<TAssociationEntity> UsingEntity<TAssociationEnt
/// <summary>
/// Configures the relationships to the entity types participating in the many-to-many relationship.
/// </summary>
/// <param name="entityTypeName"> The name of the association entity. </param>
/// <param name="joinEntityName"> The name of the association entity. </param>
/// <param name="configureRight"> The configuration for the relationship to the right entity type. </param>
/// <param name="configureLeft"> The configuration for the relationship to the left entity type. </param>
/// <typeparam name="TAssociationEntity"> The type of the association entity. </typeparam>
/// <returns> The builder for the association type. </returns>
public virtual EntityTypeBuilder<TAssociationEntity> UsingEntity<TAssociationEntity>(
[NotNull] string entityTypeName,
[NotNull] string joinEntityName,
[NotNull] Func<EntityTypeBuilder<TAssociationEntity>, ReferenceCollectionBuilder<TLeftEntity, TAssociationEntity>> configureRight,
[NotNull] Func<EntityTypeBuilder<TAssociationEntity>, ReferenceCollectionBuilder<TRightEntity, TAssociationEntity>> configureLeft)
where TAssociationEntity : class
{
Check.NotEmpty(entityTypeName, nameof(entityTypeName));
Check.NotEmpty(joinEntityName, nameof(joinEntityName));
Check.NotNull(configureRight, nameof(configureRight));
Check.NotNull(configureLeft, nameof(configureLeft));

Expand All @@ -112,7 +112,7 @@ public virtual EntityTypeBuilder<TAssociationEntity> UsingEntity<TAssociationEnt
}

var entityTypeBuilder = new EntityTypeBuilder<TAssociationEntity>(
ModelBuilder.Entity(entityTypeName, typeof(TAssociationEntity), ConfigurationSource.Explicit).Metadata);
ModelBuilder.Entity(joinEntityName, typeof(TAssociationEntity), ConfigurationSource.Explicit).Metadata);

var leftForeignKey = configureLeft(entityTypeBuilder).Metadata;
var rightForeignKey = configureRight(entityTypeBuilder).Metadata;
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Builders/EntityTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ public virtual EntityTypeBuilder OwnsMany(
Check.NotEmpty(navigationName, nameof(navigationName));
Check.NotNull(buildAction, nameof(buildAction));

buildAction.Invoke(OwnsManyBuilder(new TypeIdentity(ownedType, (Model)Metadata.Model), targetClrType: null, navigationName));
buildAction(OwnsManyBuilder(new TypeIdentity(ownedType, (Model)Metadata.Model), targetClrType: null, navigationName));
return this;
}

Expand Down
8 changes: 4 additions & 4 deletions src/EFCore/Metadata/Builders/IConventionEntityTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ IConventionForeignKeyBuilder HasOwnership(
/// <summary>
/// Configures a relationship where the target entity is owned by (or part of) this entity.
/// </summary>
/// <param name="targetEntityTypeName"> The name of the entity type that this relationship targets. </param>
/// <param name="targetEntityName"> The name of the entity type that this relationship targets. </param>
/// <param name="targetEntityClrType"> The CLR type of the entity type that this relationship targets. </param>
/// <param name="navigationToTarget"> The navigation property on this entity type that is part of the relationship. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
Expand All @@ -504,7 +504,7 @@ IConventionForeignKeyBuilder HasOwnership(
/// <see langword="null" /> otherwise.
/// </returns>
IConventionForeignKeyBuilder HasOwnership(
[NotNull] string targetEntityTypeName,
[NotNull] string targetEntityName,
[NotNull] Type targetEntityClrType,
[NotNull] MemberInfo navigationToTarget,
bool fromDataAnnotation = false);
Expand Down Expand Up @@ -552,13 +552,13 @@ IConventionForeignKeyBuilder HasOwnership(
/// <summary>
/// Configures a relationship where the target entity is owned by (or part of) this entity.
/// </summary>
/// <param name="targetEntityTypeName"> The name of the entity type that this relationship targets. </param>
/// <param name="targetEntityName"> The name of the entity type that this relationship targets. </param>
/// <param name="targetEntityClrType"> The type that this relationship targets. </param>
/// <param name="navigationToTargetName"> The name of the navigation property on this entity type that is part of the relationship. </param>
/// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
/// <returns> An object that can be used to configure the relationship. </returns>
IConventionForeignKeyBuilder HasOwnership(
[NotNull] string targetEntityTypeName,
[NotNull] string targetEntityName,
[NotNull] Type targetEntityClrType,
[NotNull] string navigationToTargetName,
bool fromDataAnnotation = false);
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Builders/OwnedNavigationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public virtual OwnedNavigationBuilder OwnsOne(

using (DependentEntityType.Model.ConventionDispatcher.DelayConventions())
{
buildAction.Invoke(OwnsOneBuilder(new TypeIdentity(ownedTypeName), clrType, navigationName));
buildAction(OwnsOneBuilder(new TypeIdentity(ownedTypeName), clrType, navigationName));
return this;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/EFCore/Metadata/Builders/OwnedNavigationBuilder`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public virtual OwnedNavigationBuilder<TEntity, TDependentEntity> OwnsOne<TNewDep
Check.NotNull(navigationName, nameof(navigationName));
Check.NotNull(buildAction, nameof(buildAction));

buildAction.Invoke(OwnsOneBuilder<TNewDependentEntity>(targetTypeName: null, new MemberIdentity(navigationName)));
buildAction(OwnsOneBuilder<TNewDependentEntity>(targetTypeName: null, new MemberIdentity(navigationName)));
return this;
}

Expand Down Expand Up @@ -676,7 +676,7 @@ public virtual OwnedNavigationBuilder<TEntity, TDependentEntity> OwnsMany<TNewDe

using (DependentEntityType.Model.ConventionDispatcher.DelayConventions())
{
buildAction.Invoke(OwnsManyBuilder<TNewDependentEntity>(targetTypeName: null, new MemberIdentity(navigationName)));
buildAction(OwnsManyBuilder<TNewDependentEntity>(targetTypeName: null, new MemberIdentity(navigationName)));
return this;
}
}
Expand Down Expand Up @@ -717,7 +717,7 @@ public virtual OwnedNavigationBuilder<TEntity, TDependentEntity> OwnsMany<TNewDe

using (DependentEntityType.Model.ConventionDispatcher.DelayConventions())
{
buildAction.Invoke(OwnsManyBuilder<TNewDependentEntity>(targetTypeName, new MemberIdentity(navigationName)));
buildAction(OwnsManyBuilder<TNewDependentEntity>(targetTypeName, new MemberIdentity(navigationName)));
return this;
}
}
Expand Down Expand Up @@ -756,7 +756,7 @@ public virtual OwnedNavigationBuilder<TEntity, TDependentEntity> OwnsMany<TNewDe

using (DependentEntityType.Model.ConventionDispatcher.DelayConventions())
{
buildAction.Invoke(OwnsManyBuilder<TNewDependentEntity>(targetTypeName: null, new MemberIdentity(navigationExpression.GetMemberAccess())));
buildAction(OwnsManyBuilder<TNewDependentEntity>(targetTypeName: null, new MemberIdentity(navigationExpression.GetMemberAccess())));
return this;
}
}
Expand Down Expand Up @@ -798,7 +798,7 @@ public virtual OwnedNavigationBuilder<TEntity, TDependentEntity> OwnsMany<TNewDe

using (DependentEntityType.Model.ConventionDispatcher.DelayConventions())
{
buildAction.Invoke(OwnsManyBuilder<TNewDependentEntity>(targetTypeName, new MemberIdentity(navigationExpression.GetMemberAccess())));
buildAction(OwnsManyBuilder<TNewDependentEntity>(targetTypeName, new MemberIdentity(navigationExpression.GetMemberAccess())));
return this;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/Metadata/IConventionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ IConventionEntityType FindEntityType(
string RemoveIgnored([NotNull] string typeName);

/// <summary>
/// Gets whether the CLR type is used by shared entities in the model.
/// Gets whether the CLR type is used by shared type entities in the model.
/// </summary>
/// <param name="clrType"> The CLR type. </param>
/// <returns> Whether the CLR type is used by shared entities in the model. </returns>
/// <returns> Whether the CLR type is used by shared type entities in the model. </returns>
bool IsShared([NotNull] Type clrType);

/// <summary>
Expand Down
20 changes: 10 additions & 10 deletions src/EFCore/Metadata/Internal/InternalEntityTypeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2962,12 +2962,12 @@ public virtual InternalForeignKeyBuilder HasOwnership(
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual InternalForeignKeyBuilder HasOwnership(
[NotNull] string targetEntityTypeName,
[NotNull] string targetEntityName,
[NotNull] Type clrType,
[NotNull] string navigationName,
ConfigurationSource configurationSource)
=> HasOwnership(
new TypeIdentity(targetEntityTypeName), Check.NotNull(clrType, nameof(clrType)),
new TypeIdentity(targetEntityName), Check.NotNull(clrType, nameof(clrType)),
MemberIdentity.Create(navigationName), inverse: null, configurationSource);

/// <summary>
Expand Down Expand Up @@ -3006,7 +3006,7 @@ public virtual InternalForeignKeyBuilder HasOwnership(
/// </summary>
public virtual InternalForeignKeyBuilder HasOwnership(
[NotNull] Type targetEntityType,
[NotNull] MemberIdentity navigation,
MemberIdentity navigation,
ConfigurationSource configurationSource)
=> HasOwnership(
new TypeIdentity(targetEntityType, Metadata.Model), targetClrType: null,
Expand All @@ -3019,12 +3019,12 @@ public virtual InternalForeignKeyBuilder HasOwnership(
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual InternalForeignKeyBuilder HasOwnership(
[NotNull] string targetEntityTypeName,
[NotNull] string targetEntityName,
[NotNull] Type clrType,
[NotNull] MemberInfo navigationMember,
ConfigurationSource configurationSource)
=> HasOwnership(
new TypeIdentity(targetEntityTypeName), Check.NotNull(clrType, nameof(clrType)),
new TypeIdentity(targetEntityName), Check.NotNull(clrType, nameof(clrType)),
MemberIdentity.Create(navigationMember), inverse: null, configurationSource);

/// <summary>
Expand All @@ -3036,7 +3036,7 @@ public virtual InternalForeignKeyBuilder HasOwnership(
public virtual InternalForeignKeyBuilder HasOwnership(
[NotNull] string targetEntityTypeName,
[NotNull] Type clrType,
[NotNull] MemberIdentity navigation,
MemberIdentity navigation,
ConfigurationSource configurationSource)
=> HasOwnership(
new TypeIdentity(targetEntityTypeName), Check.NotNull(clrType, nameof(clrType)),
Expand Down Expand Up @@ -4815,9 +4815,9 @@ IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasOwnership(
/// </summary>
[DebuggerStepThrough]
IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasOwnership(
string targetEntityTypeName, Type targetEntityClrType, string navigationToTargetName, bool fromDataAnnotation)
string targetEntityName, Type targetEntityClrType, string navigationToTargetName, bool fromDataAnnotation)
=> HasOwnership(
targetEntityTypeName, targetEntityClrType, navigationToTargetName,
targetEntityName, targetEntityClrType, navigationToTargetName,
fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention);

/// <summary>
Expand All @@ -4828,9 +4828,9 @@ IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasOwnership(
/// </summary>
[DebuggerStepThrough]
IConventionForeignKeyBuilder IConventionEntityTypeBuilder.HasOwnership(
string targetEntityTypeName, Type targetEntityClrType, MemberInfo navigationToTarget, bool fromDataAnnotation)
string targetEntityName, Type targetEntityClrType, MemberInfo navigationToTarget, bool fromDataAnnotation)
=> HasOwnership(
targetEntityTypeName, targetEntityClrType, navigationToTarget,
targetEntityName, targetEntityClrType, navigationToTarget,
fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention);

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/EFCore/Metadata/Internal/InternalModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private InternalEntityTypeBuilder Entity(
if (Metadata.IsShared(clrType))
{
return configurationSource == ConfigurationSource.Explicit
? throw new InvalidOperationException("CannotCreateEntityType")
? throw new InvalidOperationException(CoreStrings.ClashingSharedType(clrType.DisplayName()))
: (InternalEntityTypeBuilder)null;
}

Expand All @@ -96,7 +96,7 @@ private InternalEntityTypeBuilder Entity(
if (sharedTypeClrType != null && Metadata.FindEntityType(Metadata.GetDisplayName(sharedTypeClrType)) != null)
{
return configurationSource == ConfigurationSource.Explicit
? throw new InvalidOperationException("Existing nonshared type")
? throw new InvalidOperationException(CoreStrings.ClashingNonSharedType(type.Name))
: (InternalEntityTypeBuilder)null;
}

Expand Down Expand Up @@ -141,7 +141,7 @@ private InternalEntityTypeBuilder Entity(
{
if (entityType.ClrType != sharedTypeClrType)
{
throw new InvalidOperationException("Same name used for different shared type entity type.");
throw new InvalidOperationException(CoreStrings.ClashingMismatchedSharedType(type.Name));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private EntityType AddEntityType(EntityType entityType)
{
if (_entityTypes.Any(et => !et.Value.HasSharedClrType && et.Value.ClrType == entityType.ClrType))
{
throw new InvalidOperationException("CannotAddSharedTypeMatchingTypeOfNonShared");
throw new InvalidOperationException(CoreStrings.ClashingNonSharedType(entityType.DisplayName()));
}

_sharedEntityClrTypes.Add(entityType.ClrType);
Expand Down
Loading

0 comments on commit 9a7f5e7

Please sign in to comment.