Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriySvyryd committed May 14, 2019
1 parent 5c92ef8 commit acd5ca7
Show file tree
Hide file tree
Showing 21 changed files with 392 additions and 94 deletions.
1 change: 1 addition & 0 deletions EFCore.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeEditing/GenerateMemberBody/CopyXmlDocumentation/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeEditing/GenerateMemberBody/DebuggerStepThroughAccessors/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeEditing/GenerateMemberBody/DocumentationGenerationKind/@EntryValue">Copy</s:String>
<s:String x:Key="/Default/CodeInspection/GeneratedCode/GeneratedFileMasks/=Resources_002Ecs/@EntryIndexedValue">Resources.cs</s:String>
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=Microsoft_002EEntityFrameworkCore_002EAnnotations/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/CodeInspection/Highlighting/AnalysisEnabled/@EntryValue">VISIBLE_FILES</s:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static IConventionModelBuilder ForCosmosHasDefaultContainerName(
}

/// <summary>
/// Returns a value indicating whether the given schema can be set as default.
/// Returns a value indicating whether the given container name can be set as default.
/// </summary>
/// <param name="modelBuilder"> The model builder. </param>
/// <param name="name"> The default container name. </param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public static class CosmosPropertyBuilderExtensions
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static PropertyBuilder ForCosmosToProperty(
[NotNull] this PropertyBuilder propertyBuilder,
[CanBeNull] string name)
[NotNull] string name)
{
Check.NotNull(propertyBuilder, nameof(propertyBuilder));
Check.NotEmpty(name, nameof(name));

propertyBuilder.Metadata.SetCosmosPropertyName(name);

Expand All @@ -35,14 +36,13 @@ public static PropertyBuilder ForCosmosToProperty(
/// <summary>
/// Configures the property name that the property is mapped to when targeting Azure Cosmos.
/// </summary>
/// <remarks> If an empty string is supplied then the property will not be persisted. </remarks>
/// <typeparam name="TProperty"> The type of the property being configured. </typeparam>
/// <param name="propertyBuilder"> The builder for the property being configured. </param>
/// <param name="name"> The name of the container. </param>
/// <returns> The same builder instance so that multiple calls can be chained. </returns>
public static PropertyBuilder<TProperty> ForCosmosToProperty<TProperty>(
[NotNull] this PropertyBuilder<TProperty> propertyBuilder,
[CanBeNull] string name)
[NotNull] string name)
=> (PropertyBuilder<TProperty>)ForCosmosToProperty((PropertyBuilder)propertyBuilder, name);

/// <summary>
Expand Down
29 changes: 12 additions & 17 deletions src/EFCore/Infrastructure/ModelValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,21 +500,6 @@ protected virtual void ValidateDiscriminatorValues([NotNull] IModel model, [NotN
}
}

private static void ValidateDiscriminator(IEntityType entityType)
{
if (entityType.GetDiscriminatorProperty() == null)
{
throw new InvalidOperationException(
CoreStrings.NoDiscriminatorProperty(entityType.DisplayName()));
}

if (entityType.GetDiscriminatorValue() == null)
{
throw new InvalidOperationException(
CoreStrings.NoDiscriminatorValue(entityType.DisplayName()));
}
}

private static void ValidateDiscriminatorValues(IEntityType rootEntityType)
{
var discriminatorValues = new Dictionary<object, IEntityType>();
Expand All @@ -524,16 +509,26 @@ private static void ValidateDiscriminatorValues(IEntityType rootEntityType)
return;
}

if (rootEntityType.GetDiscriminatorProperty() == null)
{
throw new InvalidOperationException(
CoreStrings.NoDiscriminatorProperty(rootEntityType.DisplayName()));
}

foreach (var derivedType in derivedTypes)
{
if (derivedType.ClrType?.IsInstantiable() != true)
{
continue;
}

ValidateDiscriminator(derivedType);

var discriminatorValue = derivedType.GetDiscriminatorValue();
if (discriminatorValue == null)
{
throw new InvalidOperationException(
CoreStrings.NoDiscriminatorValue(derivedType.DisplayName()));
}

if (discriminatorValues.TryGetValue(discriminatorValue, out var duplicateEntityType))
{
throw new InvalidOperationException(
Expand Down
5 changes: 5 additions & 0 deletions src/EFCore/Metadata/Internal/ConventionAnnotatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,21 @@ private static ConventionAnnotation CreateAnnotation(
string name, object value, ConfigurationSource configurationSource)
=> new ConventionAnnotation(name, value, configurationSource);

/// <inheritdoc />
IEnumerable<IConventionAnnotation> IConventionAnnotatable.GetAnnotations() => GetAnnotations();

/// <inheritdoc />
void IConventionAnnotatable.SetAnnotation(string name, object value, bool fromDataAnnotation)
=> SetAnnotation(name, value, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention);

/// <inheritdoc />
IConventionAnnotation IConventionAnnotatable.AddAnnotation(string name, object value, bool fromDataAnnotation)
=> AddAnnotation(name, value, fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention);

/// <inheritdoc />
IConventionAnnotation IConventionAnnotatable.FindAnnotation(string name) => FindAnnotation(name);

/// <inheritdoc />
IConventionAnnotation IConventionAnnotatable.RemoveAnnotation(string name) => RemoveAnnotation(name);
}
}
Loading

0 comments on commit acd5ca7

Please sign in to comment.