Skip to content

Commit

Permalink
Add XML docs for convention classes.
Browse files Browse the repository at this point in the history
Part of #214
  • Loading branch information
AndriySvyryd committed Jun 4, 2019
1 parent 5789dae commit e6acad1
Show file tree
Hide file tree
Showing 71 changed files with 696 additions and 893 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,14 @@
namespace Microsoft.EntityFrameworkCore.Cosmos.Metadata.Conventions
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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.
/// A convention that configures the discriminator value for entity types as the entity type name.
/// </summary>
public class CosmosDiscriminatorConvention : DiscriminatorConvention, IEntityTypeAddedConvention
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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.
/// Creates a new instance of <see cref="CosmosDiscriminatorConvention" />.
/// </summary>
/// <param name="dependencies"> Parameter object containing dependencies for this convention. </param>
public CosmosDiscriminatorConvention([NotNull] ProviderConventionSetBuilderDependencies dependencies)
: base(dependencies)
{
Expand Down
12 changes: 12 additions & 0 deletions src/EFCore.Cosmos/Metadata/Conventions/StoreKeyConvention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@

namespace Microsoft.EntityFrameworkCore.Cosmos.Metadata.Conventions
{
/// <summary>
/// <para>
/// A convention that adds the 'id' property - a key required by Azure Cosmos.
/// </para>
/// This convention also add the '__jObject' containing the JSON object returned by the store.
/// <para>
/// </para>
/// </summary>
public class StoreKeyConvention :
IEntityTypeAddedConvention,
IForeignKeyOwnershipChangedConvention,
Expand All @@ -21,6 +29,10 @@ public class StoreKeyConvention :
public static readonly string IdPropertyName = "id";
public static readonly string JObjectPropertyName = "__jObject";

/// <summary>
/// Creates a new instance of <see cref="StoreKeyConvention" />.
/// </summary>
/// <param name="dependencies"> Parameter object containing dependencies for this convention. </param>
public StoreKeyConvention([NotNull] ProviderConventionSetBuilderDependencies dependencies)
{
Dependencies = dependencies;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
Expand All @@ -32,7 +31,6 @@ public class CSharpDbContextGenerator : ICSharpDbContextGenerator
private readonly ICSharpHelper _code;
private readonly IProviderConfigurationCodeGenerator _providerConfigurationCodeGenerator;
private readonly IAnnotationCodeGenerator _annotationCodeGenerator;
private readonly LoggingDefinitions _loggingDefinitions;
private IndentedStringBuilder _sb;
private bool _entityTypeBuilderInitialized;

Expand All @@ -45,18 +43,15 @@ public class CSharpDbContextGenerator : ICSharpDbContextGenerator
public CSharpDbContextGenerator(
[NotNull] IProviderConfigurationCodeGenerator providerConfigurationCodeGenerator,
[NotNull] IAnnotationCodeGenerator annotationCodeGenerator,
[NotNull] ICSharpHelper cSharpHelper,
[NotNull] LoggingDefinitions loggingDefinitions)
[NotNull] ICSharpHelper cSharpHelper)
{
Check.NotNull(providerConfigurationCodeGenerator, nameof(providerConfigurationCodeGenerator));
Check.NotNull(annotationCodeGenerator, nameof(annotationCodeGenerator));
Check.NotNull(cSharpHelper, nameof(cSharpHelper));
Check.NotNull(loggingDefinitions, nameof(loggingDefinitions));

_providerConfigurationCodeGenerator = providerConfigurationCodeGenerator;
_annotationCodeGenerator = annotationCodeGenerator;
_code = cSharpHelper;
_loggingDefinitions = loggingDefinitions;
}

/// <summary>
Expand Down Expand Up @@ -463,9 +458,9 @@ private void GenerateKey(IKey key, IEntityType entityType, bool useDataAnnotatio
{
if (key is Key concreteKey
&& key.Properties.SequenceEqual(
new KeyDiscoveryConvention(null).DiscoverKeyProperties(
KeyDiscoveryConvention.DiscoverKeyProperties(
concreteKey.DeclaringEntityType,
concreteKey.DeclaringEntityType.GetProperties().ToList())))
concreteKey.DeclaringEntityType.GetProperties())))
{
return;
}
Expand Down Expand Up @@ -690,7 +685,7 @@ private void GenerateProperty(IProperty property, bool useDataAnnotations)
var valueGenerated = property.ValueGenerated;
var isRowVersion = false;
if (((IConventionProperty)property).GetValueGeneratedConfigurationSource().HasValue
&& RelationalValueGeneratorConvention.GetValueGenerated(property) != valueGenerated)
&& RelationalValueGenerationConvention.GetValueGenerated(property) != valueGenerated)
{
string methodName;
switch (valueGenerated)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,12 @@ protected virtual void GeneratePropertyDataAnnotations(

private void GenerateKeyAttribute(IProperty property)
{
var key = property.AsProperty().PrimaryKey;

var key = property.FindContainingPrimaryKey();
if (key?.Properties.Count == 1)
{
if (key is Key concreteKey
&& key.Properties.SequenceEqual(new KeyDiscoveryConvention(null).DiscoverKeyProperties(
concreteKey.DeclaringEntityType, concreteKey.DeclaringEntityType.GetProperties().ToList())))
if (key is IConventionKey concreteKey
&& key.Properties.SequenceEqual(KeyDiscoveryConvention.DiscoverKeyProperties(
concreteKey.DeclaringEntityType, concreteKey.DeclaringEntityType.GetProperties())))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ protected virtual KeyBuilder VisitPrimaryKey([NotNull] EntityTypeBuilder builder
var property = builder.Metadata.FindProperty(GetPropertyName(primaryKey.Columns[0]))?.AsProperty();
if (property != null)
{
var conventionalValueGenerated = RelationalValueGeneratorConvention.GetValueGenerated(property);
var conventionalValueGenerated = RelationalValueGenerationConvention.GetValueGenerated(property);
if (conventionalValueGenerated == ValueGenerated.OnAdd)
{
property.ValueGenerated = ValueGenerated.Never;
Expand Down
10 changes: 7 additions & 3 deletions src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ protected virtual void ValidateDefaultValuesOnKeys([NotNull] IModel model, [NotN
/// </summary>
/// <param name="model"> The model to validate. </param>
/// <param name="logger"> The logger to use. </param>
protected virtual void ValidateSharedTableCompatibility([NotNull] IModel model, [NotNull] IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
protected virtual void ValidateSharedTableCompatibility(
[NotNull] IModel model,
[NotNull] IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
{
var tables = new Dictionary<string, List<IEntityType>>();
foreach (var entityType in model.GetEntityTypes().Where(et => et.FindPrimaryKey() != null))
Expand Down Expand Up @@ -286,7 +288,8 @@ private static bool IsIdentifyingPrincipal(IEntityType dependentEntityType, IEnt
/// <param name="tableName"> The table name. </param>
/// <param name="logger"> The logger to use. </param>
protected virtual void ValidateSharedColumnsCompatibility(
[NotNull] IReadOnlyList<IEntityType> mappedTypes, [NotNull] string tableName, [NotNull] IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
[NotNull] IReadOnlyList<IEntityType> mappedTypes, [NotNull] string tableName,
[NotNull] IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
{
Dictionary<string, IProperty> storeConcurrencyTokens = null;
if (mappedTypes.Count > 1)
Expand Down Expand Up @@ -418,7 +421,8 @@ protected virtual void ValidateSharedColumnsCompatibility(
{
foreach (var missingColumn in missingConcurrencyTokens)
{
if (!entityType.GetAllBaseTypes().SelectMany(t => t.GetDeclaredProperties()).Any(p => p.GetColumnName() == missingColumn))
if (entityType.GetAllBaseTypes().SelectMany(t => t.GetDeclaredProperties())
.All(p => p.GetColumnName() != missingColumn))
{
throw new InvalidOperationException(
RelationalStrings.MissingConcurrencyColumn(entityType.DisplayName(), missingColumn, tableName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public override ConventionSet CreateConventionSet()
{
var conventionSet = base.CreateConventionSet();

ValueGeneratorConvention valueGeneratorConvention = new RelationalValueGeneratorConvention(Dependencies, RelationalDependencies);
ValueGenerationConvention valueGenerationConvention = new RelationalValueGenerationConvention(Dependencies, RelationalDependencies);

ReplaceConvention(conventionSet.EntityTypeBaseTypeChangedConventions, valueGeneratorConvention);
ReplaceConvention(conventionSet.EntityTypePrimaryKeyChangedConventions, valueGeneratorConvention);
ReplaceConvention(conventionSet.ForeignKeyAddedConventions, valueGeneratorConvention);
ReplaceConvention(conventionSet.ForeignKeyRemovedConventions, valueGeneratorConvention);
ReplaceConvention(conventionSet.EntityTypeBaseTypeChangedConventions, valueGenerationConvention);
ReplaceConvention(conventionSet.EntityTypePrimaryKeyChangedConventions, valueGenerationConvention);
ReplaceConvention(conventionSet.ForeignKeyAddedConventions, valueGenerationConvention);
ReplaceConvention(conventionSet.ForeignKeyRemovedConventions, valueGenerationConvention);

var relationalColumnAttributeConvention = new RelationalColumnAttributeConvention(Dependencies, RelationalDependencies);

Expand All @@ -75,7 +75,7 @@ public override ConventionSet CreateConventionSet()
conventionSet.EntityTypeBaseTypeChangedConventions.Add(new TableNameFromDbSetConvention(Dependencies, RelationalDependencies));
conventionSet.PropertyFieldChangedConventions.Add(relationalColumnAttributeConvention);
conventionSet.PropertyAnnotationChangedConventions.Add(storeGenerationConvention);
conventionSet.PropertyAnnotationChangedConventions.Add((RelationalValueGeneratorConvention)valueGeneratorConvention);
conventionSet.PropertyAnnotationChangedConventions.Add((RelationalValueGenerationConvention)valueGenerationConvention);

var sharedTableConvention = new SharedTableConvention(Dependencies, RelationalDependencies);
ConventionSet.AddBefore(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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.
/// A convention that configures column name and type for a property based on the applied <see cref="ColumnAttribute"/>.
/// </summary>
public class RelationalColumnAttributeConvention : PropertyAttributeConvention<ColumnAttribute>
public class RelationalColumnAttributeConvention : PropertyAttributeConventionBase<ColumnAttribute>
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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.
/// Creates a new instance of <see cref="RelationalColumnAttributeConvention" />.
/// </summary>
/// <param name="dependencies"> Parameter object containing dependencies for this convention. </param>
/// <param name="relationalDependencies"> Parameter object containing relational dependencies for this convention. </param>
public RelationalColumnAttributeConvention(
[NotNull] ProviderConventionSetBuilderDependencies dependencies,
[NotNull] RelationalConventionSetBuilderDependencies relationalDependencies)
Expand All @@ -31,13 +27,17 @@ public RelationalColumnAttributeConvention(
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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.
/// Called after a property is added to the entity type with an attribute on the associated CLR property or field.
/// </summary>
/// <param name="propertyBuilder"> The builder for the property. </param>
/// <param name="attribute"> The attribute. </param>
/// <param name="clrMember"> The member that has the attribute. </param>
/// <param name="context"> Additional information associated with convention execution. </param>
protected override void ProcessPropertyAdded(
IConventionPropertyBuilder propertyBuilder, ColumnAttribute attribute, MemberInfo clrMember, IConventionContext context)
IConventionPropertyBuilder propertyBuilder,
ColumnAttribute attribute,
MemberInfo clrMember,
IConventionContext context)
{
if (!string.IsNullOrWhiteSpace(attribute.Name))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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.
/// A convention that configures the name and schema for a <see cref="IDbFunction"/> based on the applied
/// <see cref="DbFunctionAttribute"/>.
/// </summary>
public class RelationalDbFunctionConvention : IModelAnnotationChangedConvention
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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.
/// Creates a new instance of <see cref="RelationalDbFunctionConvention" />.
/// </summary>
/// <param name="dependencies"> Parameter object containing dependencies for this convention. </param>
/// <param name="relationalDependencies"> Parameter object containing relational dependencies for this convention. </param>
public RelationalDbFunctionConvention(
[NotNull] ProviderConventionSetBuilderDependencies dependencies,
[NotNull] RelationalConventionSetBuilderDependencies relationalDependencies)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@
namespace Microsoft.EntityFrameworkCore.Metadata.Conventions
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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.
/// A convention that configures the maximum object identifier length supported by the database.
/// </summary>
public class RelationalMaxIdentifierLengthConvention : IModelInitializedConvention
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// 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.
/// Creates a new instance of <see cref="RelationalMaxIdentifierLengthConvention" />.
/// </summary>
/// <param name="maxIdentifierLength"> The maximum object identifier length supported by the database. </param>
/// <param name="dependencies"> Parameter object containing dependencies for this convention. </param>
/// <param name="relationalDependencies"> Parameter object containing relational dependencies for this convention. </param>
public RelationalMaxIdentifierLengthConvention(
int maxIdentifierLength,
[NotNull] ProviderConventionSetBuilderDependencies dependencies,
Expand Down
Loading

0 comments on commit e6acad1

Please sign in to comment.